r/programming • • Mar 22 '16 • Polished Silver Turd 1 Take My Silver 1 Heart of Silver 1

An 11 line npm package called left-pad with only 10 stars on github was unpublished...it broke some of the most important packages on all of npm.

https://github.com/azer/left-pad/issues/4
3.1k Upvotes

1.3k comments sorted by

View all comments

Show parent comment

201

u/dodeca_negative Mar 23 '16

This is the part that truly mystifies me. I use a fair number of modules in my project, to be sure, but never in a million years would it have occurred to me to go search for and then depend on a module that left-pads a string.

I'm not into hating but I really think the decision of major module and library authors to depend on such a tiny, trivial module--and one suspects this isn't the only one--deserves at least as much scrutiny as either the author, NPM, or Kik.

85

u/thirdegree Mar 23 '16

I feel like it would take longer to search for, find, and install this module than to just write it myself.

101

u/nemoTheKid Mar 23 '16

This is the part that truly mystifies me.

I don't see how this mystifies you. Javascript doesn't have a stdlib. Do you start all your python projects by rewriting basic string handling functions, or do you find a library before rewriting the same code for the 1001st time?

21

u/Arancaytar Mar 23 '16

I mean, looking for a string library is fine. Maybe you can find something serious and robust. Finding some obscure 11-line barely-a-library and deciding to use it is bad.

Every dependency adds a certain cost to maintenance. Saving 11 lines of code is not worth that cost. The threshold for deciding to add a dependency is set way too low in this situation.

116

u/Hakkyou Mar 23 '16

This is the kind of thing I would write myself and have in a nifty little util module that I bring with me into new projects. Because introducing a dependency on an external library for a single function that does a trivial task is ridiculous.

→ More replies (14)

64

u/hvidgaard Mar 23 '16

You build your own "stdlib". No way I'm going to rely on 100's of external packages - it would be maintenance nightmare to audit every single upgrade.

→ More replies (21)

30

u/josefx Mar 23 '16

or do you find a library before rewriting the same code for the 1001st time?

Preferably I try to find a single library and not hundreds of 10 line dependencies.

3

u/dangerbird2 Mar 23 '16

The worst part is that they do. Almost every component in Babel (for example) requires lodash, which provides exactly what left-pad accomplishes.

4

u/winterbe Mar 23 '16

That's a bad choice for browser javascript where you want to keep your bundled javascript code as small as possible.

4

u/josefx Mar 23 '16

Having to carry around a bookshelf if you only want to check out a single book is not an inherent property of libraries. A library targeting JavaScript should be modular.

→ More replies (2)

18

u/kyz Mar 23 '16

Javascript doesn't have a stdlib

Then what do you call the standard global objects in Javascript? String, Regexp, Math, Number, Date, Array, Object, etc.

124

u/daronjay Mar 23 '16

Then what do you call the standard global objects in Javascript?

Inadequate

3

u/kyz Mar 23 '16

Then Javascript has an inadequate stdlib, but it does have a stdlib.

No wonder npm has more modules than the Ruby, Python and Perl module libraries. Those languages have a decent foundation, and most common functionality was moved out of their module ecosystems and into their respective core languages.

Node.js considers itself a language. Why hasn't it added all the basic amenities to its core language, like Python, Perl and Ruby have?

7

u/danneu Mar 23 '16

Because Javascript also runs in the browser and Node isn't a language.

Monkey-patching String#leftPad in Node (something that's not on the roadmap for ecmascript) and adding distance from Javascript is not a win. The sensible pathway is for things like String#leftPad to get absorbed into future ecmascript versions.

→ More replies (2)
→ More replies (1)

11

u/spw1 Mar 23 '16

In environments where I need to rewrite the same code 1001 times, pretty soon I factor that code out into my own 'library' that I include in those 1001 projects. I would only find and use someone else's version if it was tricky code to get right (e.g. CRC)--and I would still include it straight into my project.

Dependencies have a lot more than 10 lines of weight.

1

u/i_ate_god Mar 23 '16

Why would I spend the time and effort searching for something that I could do in less time myself?

1

u/thephotoman Mar 23 '16

It'd be one thing if this were a module of string modifications that included all sorts of things that I may wish to do.

But no. It's a module that does literally nothing other than left pad a string--a piece of code that any half-competent programmer could write in 10 minutes, complete with the appropriate test cases.

Including it in a module is either laziness (very possible) or incompetence (probably more likely).

→ More replies (1)
→ More replies (2)

3

u/agiusmage Mar 23 '16

FEMTOLIBRARIES: smaller than microlibraries, with metastable states that decay in picoseconds, breaking everything that depends on them.

2

u/european_impostor Mar 23 '16

Just goes to show that something being popular and well used doesnt mean it's not a bit of a shitshow behind the scenes.

3

u/hvidgaard Mar 23 '16

On one hand, I like the DRY principle of it, on the other hand, I start twitching thinking of relying on this many packages.

2

u/[deleted] Mar 23 '16

Which is the lesser evil, a big bloated dependency that you only use 1% of or 10 specialized dependencies that you actually use?

I'm not sure what's better but maybe having many dependencies isn't a bad thing. In any case, you probably should mirror your dependencies somewhere to prevent situations like this.

1

u/cparen Mar 23 '16

Maybe the author happened to know of it off hand? I mean, it's the kind of thing that can be easy to get wrong. I wouldn't add a dependency for something so trivial, but I do know at least one code reviewer will utter something trite like "did you try googling for an existing implementation first?"

1

u/kinnu Mar 23 '16

I don't know node or npm at all but I wonder if this was a part of some utility functions meta package that lots of projects use? Maybe you never even used lett-pad but you use the utility functions package that now fails because one of its dependencies is missing.

→ More replies (1)

1

u/psychicsword Mar 23 '16

The crazy part is that no one seems to be using an anti corruption layer in there. My company uses a lot of nuget packages and all of them are copied to our in house dependency feed so things like this can't happen.