ES6 modules are a breath of fresh air

Coming from ruby and python I just always accepted that modules/imports/requiring files is a complete mess and that’s just how things are. You just find the project structure that somehow works and you drag it from project to project.

It’s not a widely acknowledged problem and, let’s face it, we don’t start a new project every day. Besides, if we go with Rails and such there’s this magical autoload unicorn. It somehow works and you just don’t mess around with that.

Imagine my surprise when the breath of fresh air came from javascript community of all places. I’ve spent some time getting familiar with ES6 recently (yeah, I know, I’m a few years late) and I just couldn’t believe that file after file, directory after directory, module after module everything just worked.

I tried to figure out why, and realized that ES6 modules comply with a very simple set of rules.

  1. Your file is a module; everything inside is private.
  2. Whenever you want to export something you have to explicitly state it.
  3. When importing something you have to state exactly what you are importing and where you are importing from.

That seems simple enough for any newcomer to figure out in a matter of minutes and yet powerful enough for fine grained control of what’s visible and what is not. Good job ECMAScript folks!