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

17

u/shif Nov 30 '16

but the experience will remain and it will be easier taking the new shiny js framework

17

u/protonfish Nov 30 '16

My experience is that there is too little overlap between frameworks-of-the-week that there isn't lasting benefit. Bad development habits are more likely the reward you receive from using poor frameworks.

11

u/ngly Nov 30 '16

As much as people might shit on Frameworks, I think they've greatly increased my programming mentality and how I approach problems. React was the first framework that really taught me how to break UI down into components. I've also really adopted functional programming since learning React.

5

u/nostrademons Nov 30 '16

Curious how much experience you had before React? Swing was the first framework that really taught me how to break UI down into components, and it was available in 1997. Had I been a high-school kid a decade or so earlier, NeXTSTEP would probably have been the first framework that taught me how to break UI down into components. I adopted functional programming when I learned Haskell in 2003, and had I been a college kid a decade earlier, it would've been SML in the early 90s, or Lisp in the early 80s.

You absolutely should learn the basic software principles underlying the frameworks, but the frameworks themselves will come and go, probably in barely 2-3 years.

2

u/ngly Dec 01 '16

2 years, less than a year in product.

2

u/iffypop Dec 01 '16

Came here to say the same. Been using ASP.NET UI components for a decade. Not blaming anyone for not knowing what came before, but it's erroneous to say the last few years of JavaScript have changed the way we think about componentization.

7

u/arnorhs Nov 30 '16

When you start out learning to program (first 5-10 years) it's easy to fall into the trap of false attribution when it comes to deciding what the cause is for oneself to adopt new/better practices and improve at one's trade.

To become a really good programmer, you need to learn a lot of different languages, frameworks, platforms, etc and survive a lot of trends and legacy code and what not.

It's hard to see until you're actually there.

2

u/mrubinstein Dec 01 '16

React isn't a framework, it's a library :)

8

u/Beaulne Nov 30 '16

Thats only partly true. I worked for a company that used angular / Node, now I work using react-redux and ruby. I would have considered myself fairly seasoned with angular and JS, but moving to react (specifically redux, sagas etc) proved to be a HUGE headache. The level of complexity and hardship moving from one framework to another has been such a headache due to the huge amount of dependant technologies.

Not only are the libraries getting out of hand, but so are the paradigms... You have OOP, functional, reactive. And on top of THAT you are moving from ES2015 to 2016 to 2017.

JS as it is, is a beautiful thing, but can become a mess FAST.

4

u/bwaxxlo tckidd Nov 30 '16

Why have I never ran into this? It seems like most people who complain run into problems because they try to forcefully connect the logic behind one stack to the next. I worked with Angular before moving to React. I started working for an ember company 4 months ago and I still don't run into problems that grind me down. If it helps, start with understanding what the original project was trying to solve. Plus, most of the libraries already use the same ideas throughout. Components, routers, view, model, template, controllers, service, mixin etc. They are all the same things but just configured differently depending on the library/framework. If you already know JS, the rest of this stuff shouldn't take too long to figure out.

4

u/time-lord Dec 01 '16

The problem isn't vanilla JS + frameworks. The problem is a framework + some plugin, which works until another component updates, causing a partially broken project. Comment out the code, use a different plugin, and now you have code rot. Multiply across a few developers and a few years, and your project has become an unmanageable mess. Time to start all over again with a new framework, and lose all of the knowledge of that particular stack you've gained in the past few years.

These are issues you don't have in a more mature stack like .net or C++ or Java or even PHP.

1

u/bwaxxlo tckidd Dec 01 '16

This is why you should ensure your plugins are small. Angular 1 proved that relying on one giant framework do everything for you is a bad idea. Small libraries, despite the complaints, are fantastic at this. You can easily replace something that is broken with another one or even your own implementation. Btw, I still haven't found a broken 'plugin' to this day that somehow brings everything to a halt. A day or two of such an issue but nothing more. Which is kinda what we are paid to do.

1

u/rk06 Dec 01 '16

Exactly learning react is easier if you have experience in angular js /s

1

u/bannier Nov 30 '16

Cause they usually don't settle on worse tools