Pi/Pie Author
26 Jun 2024

Import/export of modules in Pi/Pie

This article is a draft of import/export system in Pi/Pie. As Python programmer, I think from/import is better than import/from. The latter form, which is used in JS, goes backward for the perspective of path order.

If file X, Y is in A directory, the paths of X and Y contain that of A. Let the path of file X be described as X now and let us think the paths and directory/file names of A/X.

X = A + X
Y = A + Y

This naturally makes the below:

from A import X, Y

Or

import A.X
import A.Y

A.X could be printed A/X in the file system or URL. The from/import fits the OS and internet. The only problem is the redundancy of English prepositions and verbs. I prefer the symbol so Pi/Pie imports omit the two English words.

+ A.X, Y

It is easy to imagine we can use X, Y and those are in A. The plus symbol means "to add" and importing X is equal to adding X to the module sources used in a file. The comma in the import line means X and Y are in the same directory (library).

Some people could see this as the pair of A.X and Y, that is we import A.X and Y. But this must be incorrect. If we must import one library in one import sentence, in other words, we are forbidden to import multiple libraries in one import sentence, importing A.X and Y is invalid so we easily see the dot symbol separate A and X.

Bad: (A.X, Y)
OK: (A, (X, Y))

Next is the export grammar. I think the best rule is the Python style; the function whose name starts with at least one underscore is private. The "export" word should be omitted. But should a function like __add__ be private? Or should we strictly one and two underscores?

My philosophy is:

If one-underscore means private, two-underscore also means private. "Two" includes "one" and all the states in "one" must be included in "two". So the __add__ should be private if _add is private.