News for hackers. Stuff that matters.
Re:One programmer broke the internet by deleting left-pad (2... by United857 on Monday September 06, 2021 @02:30AM (#28431024)
If you have to depend on a external library for a simple function which can be written in a intro programming course, it's a red flag.
Re:One programmer broke the internet by deleting left-pad (2... by rShergold on Monday September 06, 2021 @05:39AM (#28431985)
It seems to be really common to sling mud at the JavaScript/NPM ecosystem from developers who work in other domains.

One of the big constraints we have in front end development is that every added feature adds to the bundle size of code we have to send down the wire to the end user.

When I worked in mobile app development third party libraries tended to be very large with many many features. Only a tiny fraction of that library ends up matching your use case. However when you build you end up bundling up the whole thing into your app.

JavaScript has more of a culture of many many small hyper focused packages. The logical conclusion being single function packages like left pad.

This has two benefits. One - you have less dead code in your final build. Two - if one of your dependencies is already using leftpad you essentially get to use it "for free".

If everyone did what you are suggesting you would find multiple instances of leftpad. One version you wrote. One version your dependency wrote. One version your dependency's dependency wrote etc.

Re:One programmer broke the internet by deleting left-pad (2... by ginko on Monday September 06, 2021 @05:41AM (#28431995)
>When I worked in mobile app development third party libraries tended to be very large with many many features. Only a tiny fraction of that library ends up matching your use case. However when you build you end up bundling up the whole thing into your app.

Surely there have to be tools to process dependency libraries to strip out any unused code.

Re:One programmer broke the internet by deleting left-pad (2... by rShergold on Monday September 06, 2021 @05:51AM (#28432065)
yeah it's called Tree Shaking. It's been a massive area of improvement over the last few years. However JavaScript being dynamic can be very difficult to effectively statically analyse.

A good example: There is a library called Moment for handling dates. Due to the way the interface was built it basically can't be tree shaken. It's an excellent library but it's on the heavy side. For a while now people have been moving to libraries like Date-Fns which are collections of individual functions. This library can be tree shaken as it's obvious which functions you are using and which you are not

Re:One programmer broke the internet by deleting left-pad (2... by sime2009 on Monday September 06, 2021 @07:56AM (#28432805)
> JavaScript has more of a culture of many many small hyper focused packages.

> This has two benefits. One - you have less dead code in your final build. Two - if one of your dependencies is already using leftpad you essentially get to use it "for free".

This culture has really backfired in practice.

What we now have is a proliferation of packages which do the same thing. The problem is that it is less likely that your dependencies are going to be using the packages, even though desired functionality is the same. For example, if you have two dependencies which need to do HTML encoding, chances are that they choose different packages for that job. So now as an app developer you have to pay for both.

This combined with a culture which loves Semver but doesn't mind breaking backwards compatibility ("just update the major version!") gives a huge mix of packages which can't be fixed by tree shaking.

Re:One programmer broke the internet by deleting left-pad (2... by austincheney on Monday September 06, 2021 @07:33AM (#28432681)
As a front end developer with nearly 20 years of experience I can objectively call bullshit.

The problem is Invented Here syndrome and coddling. https://en.m.wikipedia.org/wiki/Invented_here

The reason this exists is due to a lack of leadership in the front end space. More specifically, a need to hire untrained entry level developers and deliberately not train them whether due to insecurity elsewhere and a complete inability to write documentation.

> If everyone did what you are suggesting you would find multiple instances of leftpad.

It was about 8 lines of code a child could write that you probably don’t need in the first place.

Re:One programmer broke the internet by deleting left-pad (2... by rShergold on Monday September 06, 2021 @08:04AM (#28432862)
I agree with a lot of what you're saying.

However if the threshold for not including a package is that it's 8 lines of code that would rule out using most of the functions in Lodash and Underscore.

If the threshold is not importing code a child could write that would rule out using Babel which was in fact literally written by a child.

Re:One programmer broke the internet by deleting left-pad (2... by dimitar on Tuesday September 07, 2021 @03:38AM (#28442041)
Dead code elimination can be done by a compiler like Google's Closure
Re:One programmer broke the internet by deleting left-pad (2... by Cthulhu_ on Monday September 06, 2021 @05:30AM (#28431942)
One big problem here is that Node (and Javascript)'s standard libraries do / did not have a lot of these utilities yet. It's the same with e.g. Java, so Apache Commons is one of the most common libraries to find in a Java application.

Go seems to have done a better job with a lot of utilities found in its standard library. But, it also has a mindset that it's better to just copy code than to add a dependency. Another factor there was of course that dependency management was a bit painful and fragmented until a few releases ago, unlike NodeJS which had NPM and its ecosystem not long after it came out.

Re:One programmer broke the internet by deleting left-pad (2... by tinco on Monday September 06, 2021 @04:30AM (#28431637)
If you have to depend on Node.JS to run your service, it's a red flag. Still I'm seriously considering Node.JS for every backend project we start, just because it's so much easier to hire for, and the ecosystem is so healthy. We're living in a red flag time for software development.
Re:One programmer broke the internet by deleting left-pad (2... by quonn on Monday September 06, 2021 @04:52AM (#28431732)
There‘s nothing wrong with NodeJS in principle, especially when combined with TypeScript. Can you point to something specific?
Re:One programmer broke the internet by deleting left-pad (2... by georgyo on Monday September 06, 2021 @05:14AM (#28431836)
For me personally, the fact that even a simple node project will have well over 1000 dependencies is a problem. Slightly more complex projects will have more than 10k dependencies.

Auditing is nearly impossible.

The complete lack of a standard stdlib means always relying on community packages.

Also, not a complaint directly against node directly, but for the ecosystem and developers. There is not a culture of compatibility, further fueled by the fact that multiple versions of the same dependency can be included in the same code base by different dependencies.

Coming from any other language were it is a goal to keep external dependencies down, nodejs is nightmare fuel.

Re:One programmer broke the internet by deleting left-pad (2... by michaelt on Monday September 06, 2021 @05:15AM (#28431845)
Many people judge programming languages as not just the language, but also the tools, library, community, conventions and so on.

After all, if I love Java but hate AbstractSingletonProxyFactoryBeans, I'm probably going to hate being a professional Java developer.

Some would see the left-pad incident not as an isolated oddity, but as representative of the entire NodeJS ecosystem - showing a weak standard library, a culture of pulling random, unaudited code from the internet, and rats-nest dependencies.

Re:One programmer broke the internet by deleting left-pad (2... by xupybd on Monday September 06, 2021 @04:32AM (#28431646)
Isn't Go starting to gain popularity without the downside of Node?

I'm saying this as someone that hasn't used either.

Re:One programmer broke the internet by deleting left-pad (2... by onion2k on Monday September 06, 2021 @04:53AM (#28431734)
It's much worse than that. String.prototype.padStart has been available in Node since 8.0, and browsers for a long time. It's not in IE but polyfills are common.

If your first thought is a library, whether you wrote it yourself or not, then you're doing JS badly.

Re:One programmer broke the internet by deleting left-pad (2... by Vinnl on Monday September 06, 2021 @05:14AM (#28431842)
To be fair, Node.js 8 was released in 2017; this happened in 2016.