top | item 30263122

(no title)

chenglou | 4 years ago

I help maintain ReScript (https://rescript-lang.org) and we've been rolling without an import statement for years now (basically OCaml's module system). The default is to just write `MyModule.doThis` at callsites. Sometime you do wildcard open (`open MyModule`) within the right scope. Sometime you do it at the top level for convenience (e.g. stdlib), but folks try to be judicious. And yes, you can alias a module path, e.g. `module Student = School.Class.Student`. Worth noting: the reason why fully qualified `MyModule.doThis` can be the default, is that we _usually_ dictate filenames to be unique within a project, so there's no verbose path issue nor refactoring issues (and yes this works fine... Facebook does it too).

Static analysis-wise (which is what most of the blog post's about), things are basically the same. The tradeoffs are mostly just in terms of readability. I used to be ambivalent about this myself, but looking at the growing body of GitHub TypeScript code with mountains of imports automated by VSCode, imo we've landed on a decent enough design space.

discuss

order

mutatio|4 years ago

You can do this in Rust, the imports in Rust being synonymous with your aliasing of a module path.

I guess it depends on the depth of your paths, but I'm unsure what it solves, it just moves the verbosity to call sites.

codeptualize|4 years ago

Not familiar with Rust, but I really like the ReScript (OCaml) module system.

It just gets out of the way. Verbosity is easy to prevent with "open" statements. The nice thing about those is that you can put them in a local scope where you use them (which is generally recommended).

It's just a lot more flexible and a lot less hassle.