gracelang / minigrace

Self-hosting compiler for the Grace programming language
39 stars 22 forks source link

Should `import` statements be at the beginning of a module? #337

Open apblack opened 8 months ago

apblack commented 8 months ago

Are import statements allowed anywhere in a module (like other declarations)? Or must they come at the beginning of a module?

I think that import statements must come at the start of the module, after dialect statements, but before any other statements or declarations. This is for readability, and also to make it easier for the compiler or IDE to collect all of the dependencies and perform a topological sort on them.

Right now, minigrace does not require that imports come at the start of the module. However, the spec says: "Modules may begin with one or more import moduleName as nickname statements" and (in the section on Dialects) "A module may begin with a dialect statement dialect "name" ...". These statements could be clearer: in particular, it makes sense to require that dialect, if present, comes first.

KimBruce commented 8 months ago

Agree with the rigid order as proposed.

On Sun, Dec 17, 2023 at 4:14 PM Andrew Black @.***> wrote:

Are import statements allowed anywhere in a module (like other declarations)? Or must they come at the beginning of a module?

I think that import statements must come at the start of the module, after dialect statements, but before any other statements or declarations. This is for readability, and also to make it easier for the compiler or IDE to collect all of the dependencies and perform a topological sort on them.

Right now, minigrace does not require that imports come at the start of the module. However, the spec says https://web.cecs.pdx.edu/~grace/doc/lang-spec/#importing-modules: "Modules may begin with one or more import moduleName as nickname statements" and (in the section on Dialects https://web.cecs.pdx.edu/~grace/doc/lang-spec/#dialects) "A module may begin with a dialect statement dialect "name" ...". These statements could be clearer: in particular, it makes sense to require that dialect, if present, comes first.

— Reply to this email directly, view it on GitHub https://github.com/gracelang/minigrace/issues/337, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAN2D6UD2A4K67HOJFJIGUDYJ6DF5AVCNFSM6AAAAABAYW5I32VHI2DSMVQWIX3LMV43ASLTON2WKOZSGA2DKNBUGI3TEMA . You are receiving this because you are subscribed to this thread.Message ID: @.***>

-- Prof. Kim Bruce Computer Science Pomona College