Live data from Hacker News

JavaScript Module Loaders Considered Harmful

techblog.ironfroggy.com

1–10 of 45 posts

Re: JavaScript Module Loaders Considered Harmful

#2
These complaints ring true for trivial javascript projects, however if you are building complex javascript heavy applications the equation quickly changes.

Point 1: You will almost always be transpiling your javascript. In any serious project, you will want to have lots of small files to ease development, and then concatenate into larger files to ensure optimal http loading. If you don't already do this regardless of modules, you probably should.

Point 2: If you are intentionally or serendipitously relying on script execution order, that is your bug. The module loader has helpfully exposed a bug in your code for you.

Point 3: If you have lots of modules, it is simpler to deal with a module system than mashing together a load of scripts.

This complaint should come with a severe disclaimer that it only applies to trivial applications, because as soon as you start building something complicated the arguments are just plain wrong.

Software engineering is hard, and robust software engineering practices usually only pay off once you get beyond trivial examples. The ones that work, however, pay off massively once you do use them for more complex use cases.

Re: JavaScript Module Loaders Considered Harmful

#3
I'll bite, is this article supposed to be serious?

Ad #1, maybe my projects have been too small, but I never felt lost even when using CoffeeScript as the source. I mean I can see in the comment above the module which file it relates to.

Ad #2, not sure this applies to CommonJS.

Ad #3, there are really just 2 standards. Not sure that just saying what the heck, I'll just use the global `window` object is a better solution when trying to integrate multiple different vendor libraries and your code.

Re: JavaScript Module Loaders Considered Harmful

#4
Load order is a lot of what modules are there for. If A depends on B, B needs to load first. If you are depending on side effects of the module load or other undocumented dependencies, you should Google "considered harmful" and spend a few days reading the results.

All of the issues in #1 and #3 don't actually come from modules, but from "doing it wrong" -- preprocessors and forced dependencies and all the other bad practices that have been tacked on top.

Re: JavaScript Module Loaders Considered Harmful

#5
To the point of module loaders making it difficult to understand load order, I'm not sure I understand the problem. The load order is pretty much trivial since I'm loading modules that don't execute on load. They execute on the order that I've defined, so all should be expected there. When you need an expected load order as when you're defining scripts in the document as synchronous loads, you're defining implicit dependencies. One of the great strengths of AMD systems like requirejs is that it turns implicit dependencies into explicit ones.

Re: JavaScript Module Loaders Considered Harmful

#6

These complaints ring true for trivial javascript projects, however if you are building complex javascript heavy applications the equation quickly changes. Point 1: You will almost always be transpiling your javascript. In any serious project, you will want to have lots of small files to ease development, and then concatenate into larger files to ensure optimal http loading. If you don't already do this regardless of…

For those devs, like myself, who are unfamiliar with large javascript projects, do you have a link to an open-source javascript-heavy project that fits your points?

Re: JavaScript Module Loaders Considered Harmful

#8
post #6

These complaints ring true for trivial javascript projects, however if you are building complex javascript heavy applications the equation quickly changes. Point 1: You will almost always be transpiling your javascript. In any serious project, you will want to have lots of small files to ease development, and then concatenate into larger files to ensure optimal http loading. If you don't already do this regardless of…

For those devs, like myself, who are unfamiliar with large javascript projects, do you have a link to an open-source javascript-heavy project that fits your points?

[deleted]

Re: JavaScript Module Loaders Considered Harmful

#9
Modules are evil in my experience, they have many disadvantages, much more than the writer points to.

When I looked up for some wrapper to Backbone I came across ChaplinJS: https://github.com/chaplinjs/chaplin/ and it was nice, but using the module system was a nightmare. It was so painful, that I forked it and remove the module system from the code (which was a pain, but still less painful than handling the module system). the fork is here: https://github.com/snird/Mildred and I use it in production now.

Re: JavaScript Module Loaders Considered Harmful

#10

What are the supposed benefits of using module loaders over say minifying and concatenating all your JS into one maybe two files which are then placed in script tags at the bottom of your HTML?

- Organized code (into modules)

- Explicit dependencies (instead of using the global scope for communication)

- Easier to reason about and test parts of the code

- Errors are properly isolated in a module

The post is putting module loaders (requirejs) and "using modules" (e.g. commonjs) into the same box. With browserify you end up with one or maybe two large concatenated file that you then place in script tags at the bottom of your HTML. There's no "instead".

Post reply on HN