r/javascript • • Nov 30 '16

Modern JS developer workflow makes me sad

Edit:

Wow, I would never have expected so many replies and advises. I sincerely thank you all!

I would like to highlight 3 tips that have helped me the most:

  • @sdihgusdoiu - Hard Source Webpack Plugin. This plugin was rarely given a mention in other links given what a difference it makes and how simple it is to set up compared to other solutions.
    My mental model: it calculates a hash for Webpack config and package.json. If neither a compilation unit nor the hashes changed, it reuses output of previous builds for that compilation unit.
    This results in a massive decrease in (re)build times. ~70s build became ~5s.
    I wish this would be built into Webpack itself, although I understand there are reasons why not.  
     

  • @acemarke - Definitely a subjective hint that many people will dislike: Use eval for source maps in Webpack
    Not only is it by far the fastest option for Webpack to produce, the source it emits is what the browser actually executes. No more brain-dead breakpoint jumps by Dev Tools. Now you are free to copy-paste and play around with code directly from the Dev Tools.
    Yes, it does show an ugly transpiled code instead of your beautified ES6 + JSX, but it sounds much worse than it really is. Much more reliable and predictable than inline-source-map.  
     

  • @Retsam19 - for frequently used modules consider exporting them as globals using Expose loader
    Being able to dynamically REPL require(modulePath) for any module seems not to be possible, although there are some Stack Overflow answers claiming it is. I couldn't get them working
     


Original Post:

This post is partly a rant, partly a cry for help, partly an inquiry about any tips and tricks that could improve our day-to-day work.

My company adopted a new, modern JS stack; all pretty standard:

  • React

  • Babel ES6 + JSX

  • Redux

  • Mocha

  • Webpack

  • React Router

  • lodash

  • along with their 1262 transitive dependencies (I'm not kidding here!)

As a result, my daily productivity plummeted. Honestly, I feel like x86 Assembly must have a friendlier set of developer tools.

A non-exhaustive list of issues:

  • We used to laugh at Java guys with their sluggish Maven, at C++ compilation times.
    Nowadays it takes Webpack longer to build a todo app than for a complex Java project to download all dependencies, clean project, compile all files, run all tests, create a package and upload it to repository. npm is even worse

  • So...Webpack's hot reload, the mythical feature getting universal praise.
    Apart from the fact that "hot" means "after 5 or more seconds", it comes with the worst of both worlds - sometimes it does work, sometimes it just doesn't; with no indication whatsoever whether it succeeded or not. So you spend 2 minutes figuring out why your fix didn't work, only to find out it hasn't been deployed in the first place. A colleague of mine stated: "I just don't trust hot reload. I always reload the entire page"

  • Webpack or Babel or something comes with a special, depression inducing feature: if you make a syntax error in your file, instead of displaying a clear error, it loads some random cached build from half a day ago

  • my employer can definitely find a better use for its money than me tracing build bugs of some deeply nested transitive 3rd party library that whimsically has changed it's AMD/UMD exports

  • so...source maps. I can see my original sources in Developer Tools! Usually, that is. So, let's try to add a debug breakpoint to my code!
    If you are lucky, it will stay on the line you clicked. Other times, it jumps a few lines up or down. Occasionally, it jumps to the bottom of the file. When developer tools sense that you haven't been frustrated for full 10 minutes, the breakpoint jumps to a 200kLoC app.js file, which freezes the entire Dev Tools and Chrome with it. Now, don't close Chrome at this point! If you do so, the next time you open Dev Tools, it will try to reopen the last session and freeze again. Just wait patiently for 2 minutes till Dev Tools finishes parsing the file, grab a cup of coffee. Actually, an antidepressant might be a better choice.

  • you won a lottery and Dev Tools really did stop at your breakpoint. Congrats,. Now, let's inspect some expression. Uncaught ReferenceError: X is not defined. What? Well, Babel thinks the best way to compile this piece of code:
    moment.isDate(...)
    is to translate it to:
    _moment2.default.isDate(...)
    This is done to every ES6 import. And yes, that "2" in _moment2 can and will change to "3" or just disappear, at any point.

  • Let's write some tests. Hm...they failed, let's see what's happening. Well, Chrome executes your test before it loads your sourcemaps, so it totally ignores your breakpoints. Remember that 200kLoC app.js file? That's your best bet now.

  • One of the best features of Javascript was an interactive REPL console in the browser. But that's so 2014! With Webpack/Babel, it's just not possible to get a reference to a particular module from Dev Tools Console. By design. Because best practices, man!

  • On the other hand, we have the 8th Wonder of the World, a time-travelling debugger for Redux. Last time I productively used it was never.

 

Is this...normal?  

How do you cope it?  

How is this clusterfuck touted as a state of the art in Javascript?  

Did you also become alergic to the phrase

makes it easy to reason about

 

516 Upvotes

292 comments sorted by

View all comments

Show parent comments

8

u/Senthe Nov 30 '16

A week ago I was implementing a calendar/timepicker in Ember. Pretty standard thing for a webapp. My coworker was like "okay just use some calendar jQuery plugin".

Except jQuery plugin would be a total disaster in Ember. So I wrote a calendar myself, using Moment.js. Rendering days, labels, changing months, and all that super basic stuff.

It took me 8 hours. And it worked just like I needed it to, with selecting, binding to other data etc. I didn't have to spend this time with some other person's crappy plugin and its configuration, modification and adjusting to my needs. I just did it. You may call it reinventing a wheel... For me it was 100% worth it.

2

u/nickgcattaneo Nov 30 '16

That's not really 're-inventing the wheel' though. You just said 'jQuery plugin would be a total disaster in Ember'. That's a clear use case then where investing in building your own tool is absolutely worth it since the current solutions would simply not work. Re-inventing the wheel is when you simply attempt to reproduce some current tool/plugin/etc, but are only reintroducing the exact same functioning processes/end result. Maybe you optimize it more or make its syntax more semantic, etc, but ultimately, if you're spending huge amounts of time coding this scenario, then most developers would say it's not worth the time.

3

u/Senthe Nov 30 '16 edited Nov 30 '16

The whole point is to be able to recognize cases when doing something yourself is worth it and when it's not.

For people like my coworker that I mentioned I am still some crazy person who wrote a calendar herself for "no" reason because "there are already plugins for that". He used a jQuery hours-picker plugin in the same project. It's crappy and stupid solution (IMO) but it "works". I guess sometimes it comes down to preference.

1

u/nickgcattaneo Nov 30 '16

Yea, coding is very subjective and relative to its current use, timelines, etc.

0

u/[deleted] Nov 30 '16

That's a clear use case then where investing in building your own tool is absolutely worth it since the current solutions would simply not work. Re-inventing the wheel is when you simply attempt to reproduce some current tool/plugin/etc, but are only reintroducing the exact same functioning processes/end result.

That is clearly a different definition than most people throw around on here. If you ever propose not using a framework (for anything) the response is always but but but you're reinventing wheel regardless of constraints or use case. Honestly, I really think the phrase reinventing the wheel is bullshit posturing people throw around when convenient and the goal is simply some baseless qualifier for whining. At that point they can conveniently fit the definition of the term to the context of the whining, which does happen frequently.

Usually when I hear but but but you're reinventing the wheel I want to reach my hands through the monitor until I strangle the person to death and then skull fuck their kitten simply out of spite. When I hear this during a job interview I will happily nod, but that resume just jumped to the bottom of the pile.

2

u/nickgcattaneo Nov 30 '16

Haha. There's tons of solutions that can be implemented for any scenario/environment/etc. Frameworks are simply great for business continuity, large scale projects, etc => They're hardly necessary for your own personal development/etc. It's all relative and anyone that hammers others for their own development choices relative to their own workspace/projects, probably don't have a solid understanding of these technologies in the first place.

1

u/Thought_Ninja human build tool Dec 02 '16

You seem pretty aggressive, not sure i would want to work for you...

1

u/[deleted] Dec 02 '16

I want to be able to get my work done. End of story. The ideal environment is where I can get all my work done in the first two to three hours of the work day and then dedicate the rest of the work day to open source projects or helping out teammates or dividing time between various other office assignments. Dicking around all day with crippled code for stupid people and wasting huge blocks of time load pages or running build tasks drives me absolutely fucking insane. I know there are mentally crippled developers who need this madness. I know my level of balls to the wall get the shit done is not for everybody. At the end though people are either wasting time or they are productive and I really don't give a shit for their excuses or sad sob stories when they are making me suffer with wasting my time.

1

u/Thought_Ninja human build tool Dec 02 '16

I call that 'commitment to framework' and I highly encourage it.

Our tech stack is mostly React, but similar principal, if it touches the DOM, use your dedicated view library.

When I said 'reinvent the wheel' I meant building out an entire tooling ecosystem like WebPack or Gulp.