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

9

u/flitsmasterfred Nov 30 '16

I coped by moving carreer; doing python on backend now; python 3 and Django are pretty glorious way to make money.

4

u/paooolino Nov 30 '16

what would you use for building a single page web app? Django and Python are fantastic, but it's all about the server-side.

8

u/here-to-jerk-off Nov 30 '16

vue.js doesn't technically require node

1

u/[deleted] Dec 01 '16

[removed] — view removed comment

1

u/here-to-jerk-off Dec 01 '16

I mean you can use vue.js as a library without the whole build environment, you lose out on some of the modern javascript stuff but you don't have to deal with the node ecosystem.

"how do you build a SPA with Django?"

If that was the question, vue.js as a REST client.

6

u/muyuu Nov 30 '16

Maybe not doing everything a single page web app? I think Angular does the trick, but then again I'm stuck in ~2015 because it's really tiresome to do stuff in the front-end, esp. when your main job is something else entirely (C++, functional languages, etc). It's just a bit of a nightmare how quickly things go "out of fashion" ever since I made my first "interactive website" in the late 90s.

13

u/seriouslulz Nov 30 '16

You rarely need an SPA anyway

5

u/ninepointsix Nov 30 '16

No one needs it. But it certainly improves the user experience on bad connections if the entire UI doesn't disappear for big chunks of time every time you click on something.

8

u/The_yulaow Nov 30 '16

Browser cache already solved that problem years ago. Today you should use an SPA only if you are building a Googledoc-like application on the browser. Imho.

1

u/Senthe Dec 01 '16

You think there's no gains for persisting state of application across multiple pages without need to make additional requests and backend changes?

1

u/bannier Nov 30 '16

Offline ?

2

u/[deleted] Nov 30 '16

I think he is recommending letting that be somebody else's job.

I would recommend looking into elm. I only have a small amount of experimental play with it, but this has already surprisingly impressed me a whole lot. I heard a podcast about it that got me more interested it it. They explained how the focus of elm is all about the user experience, the user being the programmer. They actually remove features that add too much complexity and focus on just the ones that make things easier for the programmer. There is a huge focus on the experience of getting started with it. They focus on constantly improving the compiler error messages so they are as helpful as they can possibly be. Companies are reporting using it for over a year in production without ever experiencing a single javascript exception. The point of the strict but flexible type system and compiler is that if it compiles, it probably just works. You need to write a lot less tests to verify behavior, the compiler does a lot of that for you. I had some aha moments where I realized I have been implementing a compiler in my tests, but then reimplementing that part of the compiler for each part of my code as more tests. In elm they just have a compiler for that stuff. When developing, you can just have the elm reactor going and then just visit pages in your browser. Any needed compilation will happen automatically and any compiler errors will appear in the browser. Then all you have to do is actually read the message and it tells you exactly how to fix the problem. I'm not sure if that would really scale for a real app, but going through the official starting tutorials was nice. Oh and that is another thing. The official docs have really nice getting started tutorials that both help you to get started, explain the core concepts, and help you understand why the type system and compiler are helpful things. In my career I have gone from loving types, to hating types, to realizing types can be a good thing when done properly like elm does. Before trying elm I had almost no experience with functional languages and was kind of scared of the idea, especially since Elm is compared a lot to Haskell which is notoriously confusing to learn at first. Another thing that impressed me about Elm is the way they encourage you to get started with it in a real project. Normally with a new technology I have this hope that I can slowly introduce it, only to find out I can't and I would have to rewrite an entire project with it or start a new one with it. Well with Elm they say all the success stories they hear are from people gradually introducing it to an existing project. So yeah try it out.

2

u/[deleted] Nov 30 '16

Is elm full stack? I heard about it, only good things, but whats about frontend and backend? Also, how about reliability, js frameworks go out of date or support like crazy these days, is Elm interprise ready? If not is it at least freelance ready, or is it only for personal projects and just solo playing?

2

u/[deleted] Nov 30 '16 edited Nov 30 '16

You can't use it on the server side, at least I don't think you can. Elm is still new and you will probably find missing pieces that you will have to work around. But you can use it in combination with other technologies. I don't have a lot of in depth knowledge about it, but I know some projects use both Elm and React. I would think some websites could get away with using only Elm on the frontend if they are willing to just not create features that Elm is not good for. The benefits of doing that might outweigh the costs as it should greatly simplify development and reduce bugs. But this is largely just me speculating about stuff I don't have in depth knowledge about, based on the knowledge and experience that I do have.

1

u/djslakor Dec 01 '16

At least you wouldn't have to worry about people trying to hire you.

1

u/flitsmasterfred Dec 05 '16

We don't do that 'full stack' nonsense; server-side and front-end are so different so we have other people to wrangle with JS/CSS.

1

u/vcamargo Nov 30 '16

I'd genuinely like to hear the story about this change. Would you mind to share with us?

1

u/flitsmasterfred Dec 05 '16

It kinda happened, started at the company as technical front-end, some changes in workforce left a gap in the python group and I rolled into it and got hooked on python. It is extremely expressive and productive, especially with django. I still dabble in node.js but is is painful and annoying for anything substantial.

0

u/djslakor Nov 30 '16

For now. You're missing out while the world moves more and more towards JS (which is inevitable on the front end anyways).

What will you do when Python+Django gets more alienated and your JS skills are more out of date?