I'm designing a simple OO programming language.
It's statically typed, compiled, and executed by a VM – similar to Java.
The difference is that I don't want to have such a strong emphasis on OOP. The code itself will mostly resemble C++ (classes, functions, and variables allowed in the file scope).
One of the things that I need to have is a module system. I have the following figured out:
- Every file is a module (once compiled) – like Python
- Programmers must import a module with the
import
keyword, which causes the compiler to search for modules in standard directories and the file directory (the VM has to do this at runtime as well)
And now I have no idea how should I introduce the concept of submodules and module hierarchy.
One option, for example, is to depend on the directory hierarchy, so that import engine.graphics.renderer
would expect to find a directory called "engine" in the working directory, and inside a directory called "graphics", with a module called "renderer".
What are the drawbacks of such a design? Am I missing anything?
Best Answer
Take a look at Python's package/module hierarchy/organization, and especially in historical aspect, major additions over the course of years, most importantly the latest ones. Probably, there is no sense in inventing the wheel.
I do not know how far you want to go with your language, eg
I guess, Java may be another interesting example. Things can be learned from Erlang's way as well (eg https://stackoverflow.com/questions/2968914/code-hot-swapping-in-erlang).
There is a whole lot of design issues (some touched above) if you plan to see your programming language mainstream one day. Fortunately, there are great examples out there.
Some directions programming language module/package/library system design should address: