r/javascript • • Mar 26 '16

You Have Ruined Build Systems

http://you-have-ruined-build-systems.surge.sh/
0 Upvotes

23 comments sorted by

13

u/wreckedadvent Yavascript Mar 26 '16

But, removing the need for Brunch, we also remove the need to either force CommonJS-ing everything or put modules: false in our configs. With Brunch, I had to do the latter because otherwise a user of my pack wouldn’t be able to declare template-generation functions in a natural way that would be possible without Brunch. Heck, I have written purely client-side libraries, why in the world would anyone want to require() them to reuse on a server? Node doesn’t have addEventListener as well as document.createDocumentFragment! I honestly hate all this CommonJS/AMD intervention on the platform these standards weren’t intended for. Why complicate all things instead of letting scripts load just in the order they appear?

I feel like this betrays a lack of experience in trying to organize medium-to-large-sized javascript apps. We didn't make things like requireJs or webpack because it was just a Fun Thing To Do, but there was a real problem being solved in terms of trying to organize larger applications. It simply just doesn't scale to manually organize your files when you've got a non-trivial application, and encourages you to make very very large files just so that you don't have to do this, among other unpleasantness (like relying on gobals, since that's the only way to organize code without modules).

Also, the "CommonJS/AMD intervention" was standardized: it's called ES6 modules. It's pretty ballsy to say the platform wasn't intended for module-based organization at this point.

3

u/flamingspew Mar 27 '16

Everyone's been running around fatigued and I've just been sitting here deploying dozens of production apps with grunt.

-1

u/[deleted] Mar 26 '16

I feel like this betrays a lack of experience in trying to organize medium-to-large-sized javascript apps.

Is 8K SLOC a medium or large sized javascript app? Nope, it's just a website control panel frontend.

It simply just doesn't scale to manually organize your files when you've got a non-trivial application, and encourages you to make very very large files just so that you don't have to do this

With Grunt/Gulp you don't have to do this manually. You get the same bundle in the end.

like relying on gobals, since that's the only way to organize code without modules

UglifyJS has an option to wrap everything in a closure. No need to pollute the global namespace. Export only what you need, no problem.

It's pretty ballsy to say the platform wasn't intended for module-based organization at this point.

Not so much native support yet. And bringing in another 90-to-100 KB to get it running on ES5 target is no less ballsy.

So alas, we'll stick with grunt-contrib-coffee and grunt-contrib-uglify instead of Browserify and ES6 modules.

8

u/wreckedadvent Yavascript Mar 26 '16

With Grunt/Gulp you don't have to do this manually. You get the same bundle in the end.

I'm very confused. You're talking about nativism, don't-over-complicate-it, keep-it-simple-stupid but still want to organize your files through grunt/gulp/broccoil/whatever?

How exactly is it not manual if you're telling grunt/etc what order to load your files? Do you just have a few globs and hope for the best?

UglifyJS has an option to wrap everything in a closure. No need to pollute the global namespace. Export only what you need, no problem.

You missed my point. If file A wants to talk to file B, you need to put something on the global space without a module loader, or rely on weird tricks, like the local storage item changed event. I don't know a lot of people who are super happy about relying on globals like this.

Not so much native support yet. And bringing in another 90-to-100 KB to get it running on ES5 target is no less ballsy.

My point was the standard of the javascript language calls for module-based organization.

Also, there is no module loader ever that adds 90-to-100kb to run on an ES5 target. Most modern ones have overhead in the realm of bytes, and even requireJs, which does a buttload of async file loading stuff, is somewhere in the 10-20kb range and has an entire runtime for dynamically loading in more files.

I'm not really sure where you got that figure, but you're almost certainly being disingenuous to me by including some huge unnecessary thing like regenerator.

1

u/Democratica Mar 26 '16 edited Mar 26 '16

You know what the author is trying to convey? I think he perceives that the abstraction is unbalanced versus the benefit. Where the article fails is that it tries to get the reader to be swayed to that opinion.

To me, you do it your way, I do it my way. We both create beautiful code which is elegant and easy to understand and I am happy.

I personally feel that the ecosystem is falling away from mastery of purity in the code and falling into the trap of augmentation (which is a similar opinion to the author). Does that make sense to you? This is of course my opinion.

I like this question: what is the least amount of code (complexity) I can bring into a system to make it function?

3

u/wreckedadvent Yavascript Mar 26 '16

It's just very weird to hear the nativist argument against the language standard. I recognize we're in a very high-churn situation and there's a lot of non-standard extensions like JSX and CSS preprocessors, but that's all of the more reason to promote these standard way of doing things, not shun them.

2

u/Democratica Mar 27 '16

Just to clarify I agree, and want to delve deeper into the fears and the solutions.

1

u/Democratica Mar 27 '16

Personally, I think the imports are kind of strange, a symptom of the language's lack of focus--if we had standard libraries, then it makes sense. We are of the same opinion. What scares me off in JavaScript is that this thing is a monolith and it became one very quickly, on a foundation which is possibly the most inconsistent in any language. I lack trust in it and this lack of foundational trust flows outward into those who attempt to patch the cracks. Does that make sense?

1

u/wreckedadvent Yavascript Mar 27 '16

I believe I understand what you're saying, but I don't think I necessarily agree. Javascript has always been a bit of a mutt of a language - the creator wanted a scheme interpreter, but had to add "java semantics" to make everyone else happy with it. Thus, we have a language where basically every important abstraction is based off of functions, yet still has things like new.

Something to keep in mind is the javascript community is probably one of the most diverse, since it's your only real option to talk to the web. That means we have everyone from rubyists, enterprise developers, functional programmers - you name it, they have to use javascript. A language that can service all of those groups of people, I think, inherently has to have a little bit of a lack of focus.

As for imports, I think they're fine. They remind me both of modules that we already had, and modules in other languages, f# in particular.

-1

u/[deleted] Mar 27 '16

It's just very weird to hear the nativist argument against the language standard.

My argument is this: write ES6 for ES6-compliant browsers or controlled environments like servers (where you are completely in charge of all available computing power and take full responsibility of what you do with it), write ES5 for everything else and don't make users suffer by throwing 100KB bloatware at them just because you feel more comfortable writing ES6 when your users can't run it natively with no significant overhead.

I'm not against the language standard, we just are not ready to use it as a complete replacement for what we have now.

1

u/Cody_Chaos Mar 27 '16 edited Mar 27 '16

write ES6 for ES6-compliant browsers or controlled environments like servers (where you are completely in charge of all available computing power and take full responsibility of what you do with it), write ES5 for everything else

Why not just...use babel?

don't make users suffer by throwing 100KB bloatware at them just because you feel more comfortable writing ES6 when your users can't run it natively with no significant overhead

Or you could write ES6, transpile to ES5, and get the best of both worlds?

Edit: Ah, I see from your other thread that you dislike the size of the babel-polyfill. You don't actually need to include it to use babel, you know. Figure out what features you want, figure out what browsers you need to support, use whatever polyfills make sense for you. It's absolutely incorrect to suggest you need 100kb of polyfills to use Promises or whatever.

-1

u/[deleted] Mar 27 '16

Or you could write ES6, transpile to ES5, and get the best of both worlds?

...And get 100 KB overhead if you want to use the features that really matter.

You don't actually need to include it to use babel, you know.

I know but without it ES6 becomes just another CoffeeScript, because:

It's absolutely incorrect to suggest you need 100kb of polyfills to use Promises or whatever.

You need 100 KB of polyfills to use generators, symbols, new array methods etc in ES5 environment. Together with promises, yes. That's what I had called significant features. And yes, I don't see any profit of ES6 without them. Syntactic sugar for lambdas and classes? CoffeeScript can handle that just fine. Modules? Nothing new.

What's really sad is that the most interesting ES6 features like proxies cannot be polyfilled at all, because they absolutely require proper underlying JS engine support.

0

u/[deleted] Mar 27 '16

the abstraction is unbalanced versus the benefit

This. Both articles I recently posted are actually all about this.

Same goes for other frontend development aspects, such as viral Angular/React obsession (and before this - jQuery/Bootstrap obsession). Bringing all that overhead to fields where you keep everything slain and pimple plain and simple and still get things done efficiently.

Probably not everyone understands this but there are countries where internet traffic still matters. Mistargeting for fancy fads can cost someone innocent money.

1

u/Democratica Mar 27 '16

Yeah. I like to see that I am not alone, :)

0

u/[deleted] Mar 27 '16 edited Mar 27 '16

Sorry for not being clear enough, it was late night here in Ukraine. (Btw, pardon my English too)

You're talking about nativism, don't-over-complicate-it, keep-it-simple-stupid but still want to organize your files through grunt/gulp/broccoil/whatever?

"Whatever" can include a plain npm runscript or even a standalone shell script. Grunt was just an example.

How exactly is it not manual if you're telling grunt/etc what order to load your files? Do you just have a few globs and hope for the best?

Do you remember we are talking about client-side? Its the place where any action entry points usually run independently of the place they are actually situated, as the result of some events. In our particular case, eveything is loaded before the DOMContentLoaded event is fired, and any entry point runs after this event, and the order of loading really doesn't matter as long as it happens this way. Moreover...

You missed my point. If file A wants to talk to file B, you need to put something on the global space without a module loader, or rely on weird tricks

And my point was that just a single file (bundled from file A and file B and minified) gets sent to the browser. And if source file A wants to talk to source file B, they don't need to export anything into global scope at all, they can call each others functions within that IIFE I was talking about.

I'm not really sure where you got that figure, but you're almost certainly being disingenuous to me by including some huge unnecessary thing like regenerator.

Again, sorry for the late night confusion, I referred to the size not just of a module loader but to the size of a complete emulated ES6 environment on ES5 target (and yes, it's based on babel-polyfill which yes, includes Regenerator... if you know any better alternatives, I'm all ears).

2

u/wreckedadvent Yavascript Mar 27 '16

Your english is mostly fine. At least, I don't think we're doing any miscommunication due to your english skills.

Again, sorry for the late night confusion, I referred to the size not just of a module loader but to the size of a complete emulated ES6 environment on ES5 target (and yes, it's based on babel-polyfill which yes, includes Regenerator... if you know any better alternatives, I'm all ears).

I would ask you to keep in mind that the babel-polyfill is a truly massive polyfill attempting to create a full and complete ES6 environment. This blows the cost-reward ratio right out of the water, as it includes some things which are just painful to try and emulate on an older environment, like generators.

For most consumers, the important parts of ES6 are the syntax changes. Fat arrows give a standard way to capture this, classes a standard way to create prototype chains, modules a standard way to organize code, etc. Babel can downstep your ES6 syntax into ES3/5 just fine, without any massive polyfill.

We've always been in a situation where there was parts of the latest and greatest that just can't be polyfilled. For the longest of times, it was getters and setters. These just really cannot be reasonably emulated on an ES3 environment, as is 'strict mode'. So there's always been some kind of restraint when writing against the latest standards.

If you ES6 modules and downstep it with babel, then use something like jspm, webpack, browserify, rollup, whatever, you will not occur this 100kb overhead.

0

u/[deleted] Mar 27 '16

I would ask you to keep in mind that the babel-polyfill is a truly massive polyfill attempting to create a full and complete ES6 environment.

And if I plan to write ES6 I never think about partial and incomplete environment. What's the point of half-baked solutions? We already have plenty of them!

For most consumers, the important parts of ES6 are the syntax changes. Fat arrows give a standard way to capture this, classes a standard way to create prototype chains, modules a standard way to organize code, etc. Babel can downstep your ES6 syntax into ES3/5 just fine, without any massive polyfill.

If everything I wanted were the syntax changes and classes, I'd stick with CoffeeScript. Its syntax is perfect for me. But I really want all the features that make ES6 really superior to any of those ***Scripts. And when I'm speaking of ES6, I'm speaking of it as a whole, not some subset of it. When we can use fat arrows but not generators, it's not ES6, it's a parody.

We've always been in a situation where there was parts of the latest and greatest that just can't be polyfilled.

Yes, ES6 proxies can't, but to some point we can live without them.

If you ES6 modules and downstep it with babel, then use something like jspm, webpack, browserify, rollup, whatever, you will not occur this 100kb overhead.

But in order not to occur this overhead, I'll be forced to use a very small subset of ES6, which eliminates the entire point of moving to it.

2

u/wreckedadvent Yavascript Mar 27 '16

Well, I'll guess we'll have to agree to disagree, then. I'm really excited for the future of libraries that can ulitize proxies, generators, and such in really creative ways, but I don't need them in my day-to-day. I don't consider working without them a "parody" of ES6, since they were mostly intended for library authors anyway. Even stuff like promises are just a native implementation of A+, which we've had for a while in libraries like Q.

The main benefit over using ES6 instead of coffeescript, livescript, whatever, is that it's the standard. CS has mostly fallen out of favor, at least on places like here. While people can debate about whether or not ES6 is too bloated, too influenced by sugary compile-tos like coffeescript, or whatever, the one thing that people cannot deny is it is the standard, and it is the future. One way or the other, we'll all have to learn it.

Of course, it would be non-trivial to convert over from CS to ES6, particularly the 8kloc that were talking about earlier, so I don't expect you to just drop everything and rush to it. Just something to keep in mind when you start new projects, or write blog posts about just using it instead of ES6.

1

u/[deleted] Mar 27 '16 edited Mar 27 '16

but I don't need them in my day-to-day

I envy you at some point because these features are going to make things so much easier that 8kloc can become 1kloc at most with them.

since they were mostly intended for library authors anyway

I'm one of them. The libraries are for our internal usage though.

Even stuff like promises are just a native implementation of A+, which we've had for a while in libraries like Q.

Promises are not so hard to polyfill.

The main benefit over using ES6 instead of coffeescript, livescript, whatever, is that it's the standard.

If you have to encounter ES6-compliant browsers only, I envy you once again. We still have to support IEs 9+, Safaris and mobile Blinks 30+ (Android 4.4+ - not so much of arrow functions there).

whether or not ES6 is too bloated

ES6 itself is just fine. Its emulation is too bloated though.

One way or the other, we'll all have to learn it.

I'm not against learning it, not even against using it in a controlled environment. I just think it's not wise yet to release this beast into the wild.

Of course, it would be non-trivial to convert over from CS to ES6, particularly the 8kloc that were talking about earlier

Oh no, those 8kloc were written in a terrible mixture of ES3 and ES5. And since it's just an admin panel it will never be targeted at outdated browsers, so I assume it will be refactored in pure ES6 without any babels-shmabels.

Just something to keep in mind when you start new projects

Again, target analysis first, personal preference later. That's what I'm trying to say across both threads.

Well, I'll guess we'll have to agree to disagree, then.

Fine then.

1

u/spacejack2114 Mar 27 '16

FYI if you're building a single AMD bundle, almond.js can invoke your app's main entry point. Minified it's < 3K.

5

u/ninth_reddit_account Mar 27 '16

I feel articles like this are misguided. These build tools aren't ruined, nor are they bad. They just might not be suitable for your use case.

Want a tiny scaffold for your projects? Just shove it up in a git repo, and start each project by cloning it. Want to 'bundle' all your scripts up? Just concat the files.

As your project and needs grow, you'll probably start to run into problems or identify optimisations that can be made. Chances are others thought the same, and there's tools out there to solve them.

0

u/[deleted] Mar 27 '16

What does Brunch allow to do you can't do with just Grunt, Gulp or plain NPM runscripts? I honestly don't see any added value brought up with such a tool.

Want a tiny scaffold for your projects? Just shove it up in a git repo, and start each project by cloning it.

For my next project, I already did this. See z5-skel which is a next-gen version of z9-kickstart sans 999.css :), even includes a simple server (not with a watcher though) and is entirely runscript-based.

1

u/Cody_Chaos Mar 27 '16

Why complicate all things instead of letting scripts load just in the order they appear?

Because modules are a vastly more robust solution?

We can discuss the quality of the tools; I'd even agree with a lot of your criticisms of, eg, brunch. But arguing against modules as a language feature seems a bit odd, firstly because they're already here and not going away, and secondly because they work really well.