grain
grain copied to clipboard
Considering constraining includes
currently grain allows includes anywhere in the top level of your program for example the following program is valid:
module Main
include "a"
print("b")
include "c"
Two reasons we shouldnt allowed this are in a larger program it can be hard to tell what modules are currently in scope and what the modules dependencies are and another one is considering the program above if the module c
had the line print("c")
in it you could reasonably expect the printing order to be
b
c
as thats the order of the statements but in reality it will be
c
b
which may be confusing.
an argument for keeping the ability in is when debugging it can be helpful for importing a module such as runtime/unsafe/debugPrint
quickly to print an unsafe value. so instead of erroring when we hit an include later on it probably makes the most sense to raise a compiler warning helping to ensure best practice of keeping your includes at the top of the file.