grain icon indicating copy to clipboard operation
grain copied to clipboard

Considering constraining includes

Open spotandjake opened this issue 1 year ago • 0 comments

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.

spotandjake avatar Aug 09 '23 04:08 spotandjake