r/ProgrammingLanguages • u/Tasty_Replacement_29 Bau • Apr 16 '26
Requesting criticism Module and Import
For my language, Bau, I currently use the following modules and import mechanism (I recently re-designed it to move away from Java style fully-qualified names), and I would be interested in what others do and think. Specially, do you think
- aliasing only on the module identifier is enough, or is aliasing on the type / method name / constant also important?
- In a module itself, does it make sense to require
module ...or is the Python style better, where this is not needed? I like a simple solution, but without footguns. - It's currently too early for me to think about dependency management itself; I'm more interested in the syntax and features of the language.
Ah, my language uses indentation like Python. So the random below belongs to the previous line.
Here what I have now:
Module and Import
import allows using types and functions from a module. The last part of the module name is the module identifier (for example Math below), which is used to access all types, functions, or constants in this module. The module identifier maybe be renamed (AcmeMath below) to resolve conflicts. Symbols of a module may be listed explicitly (random); the module identifier may then be omitted on usage:
import com.acme.Math: AcmeMath
import org.bau.Math
import org.bau.Utils
random
fun main()
println(Math.PI)
println(Utils.getNanoTime())
println(random())
println(Math.sqrt(2))
println(AcmeMath.sqrt(2))module defines a module. The module name must match the file path, here org/bau/Math.bau:
module org.bau.Math
PI : 3.14159265358979323846
View all comments
Show parent comment
1
u/Tasty_Replacement_29 Bau Apr 17 '26
> Is this for a scripting-like language where the contents of all imports are processed when this module is run?
Actually, no: my language is a systems programming language and more close to Java. For example, it is fully typed. But types are inferred, and I'm actually considering just having "=" for both assignment and re-assignment. I know, this is kind of risky. For my language, having a really minimal syntax is important, but safety is also important.
> It looks a bit lonely there! It's not helped by this indent style not a closing block delimiter which would make it cosier.
My language is indentation-based, so I thought making imports indentation-based makes sense. For example, types are defined like this:
And so on. One alternative would be:
but that would look kind of repetitive if you have multiple:
... and so I think the indentation style is best, for my language.
Actually, no, because when using, the module name / alias needs to be specified; and it is not allowed to import
randomvia symbol import twice.