Live data from Hacker News

NPM and Left-Pad: Have We Forgotten How to Program?

haneycodes.net

761–770 of 887 posts

Re: NPM and Left-Pad: Have We Forgotten How to Program?

#761
post #722

Earlier quoted context omitted.

Doing a for loop is not equal to re-inventing the wheel. Words and phrases have lost their meaning nowadays. By the JS community's standards if I wanted code to capitalize the 3rd or sometimes 4th letters of a string, they would be 2 different npm modules. Maybe they didn't forget how to program, as the article implies; maybe they never knew how to program in the first place.

Writing your own solution, when you could use a common widely known solution, exactly matches both writing your own left pad and inventing your own wheel. > By the JS community's standards if I wanted code to capitalize the 3rd or sometimes 4th letters of a string, they would be 2 different npm modules. If there was, it would have been published and people would be depending on it. Instead, people use the stdlib firs…

But surely the really concerning part is despite their very wide usage, these dependecies turned out in some cases to be poorly coded functions indeed. Throughout this whole thread are examples where these one or two line "modules" have poor runtime performance, miss key cases in the one single thing they claim to do, and in the very worst cases, those small "modules" themselves are depending on many more "modules".

Diseases turtles all the way down.

Re: NPM and Left-Pad: Have We Forgotten How to Program?

#762
post #706
post #685

Earlier quoted context omitted.

Would people automatically update to the new versions of the libraries you mentioned? The problem with unpublishing is that it changes an existing version. If instead of depublishing a correctly versioned empty module named leftpad was pushed to npm (increment major, because a non-implementation is incompatible with an implementation), there would not be half as much pain. As long as unpublishing exists, micromodules…

Which means unpublishing is the problem, not micromodules (in this particular case).

Absolutely true, but the scale of the problem multiplies with micromodules. More unpublishables are worse than less.

Re: NPM and Left-Pad: Have We Forgotten How to Program?

#763

What I don't get about Left-Pad, shouldn't they have used Arrays.join for better perormance?

Array performance isn't always better than string concatenation. In this test case it comes out slower: https://jsperf.com/left-pad-arrays/3 But ultimately it doesn't matter in the least for 99.9% of use cases: https://blog.codinghorror.com/the-sad-tragedy-of-micro-optim...

Interesting - well I thought if it is being used by thousands of libraries it might be worth optimizing.

I just tried in NodeJS, you could also just instantiate an Array of a given length and join it with spaces, like this.

var x = new Array(5);x[4] = "abc";x.join(" ");

No idea if it could be faster - but the test you linked to pushes spaces into the Array.

Re: NPM and Left-Pad: Have We Forgotten How to Program?

#764
post #640

Earlier quoted context omitted.

Straight-up C is not at all suitable for safety-critical software. C plus various bolt-on tools for static analysis and the like can be usable, but is always going to be less effective (IMO) than a unified language where every tool is working according to the same rules. There might be a few legitimate use cases for C, but I've seen people pick it for the wrong reason so often (and using C because "it would be perfor…

You would have to argue with the overwhelming majority of safety-critical software that is and has been for decades, written in C... Of course, static analysis is always used in combination with proper coding style... but that is just the normal (professional) C development environment.

You just have to use the right libraries:

https://github.com/Adaptv/ribs2

Re: NPM and Left-Pad: Have We Forgotten How to Program?

#765
post #736
post #705

Earlier quoted context omitted.

> This was a failure on npm's side by including a functionality that allows users to trivially remove packages from a package management system that is used by hundreds of other packages, something that most major package management systems have decided was a bad idea. That is emphatically not the problem. The author of those modules could have just as easily modified the code instead of deleting it: function leftpad…

You can't republish with the same version number, so you would be protected if you're pinned to a specific release.

At which point you don't get bug fixes. This is an old problem and there is no good solution.

Re: NPM and Left-Pad: Have We Forgotten How to Program?

#766
post #426

Earlier quoted context omitted.

If you want to build is-bigger-than-5 yourself, I recommend pulling in fivejs[1] as a dependency. [1] https://github.com/jackdcrawford/five

Why is English the only language in which "Five" is capitalized?

Five would only be capitalized at the beginning of a sentence.

You wouldn't write: "I saw Five of my friends last night."

Re: NPM and Left-Pad: Have We Forgotten How to Program?

#767

Earlier quoted context omitted.

A module doesn’t solve that kind of type confusion, though. Static typing does. The next best thing in JavaScript is passing consistent types of values to your functions, so just write function isPositiveInteger(x) { return x > 0 && Number.isInteger(x); } and always pass it a number. (Of course, this shouldn’t even be a function, because JavaScript is confused about the definition of “integer” – maybe you really want…

I would swap the expressions on each side of the '&&' around. While JS doesn't care (as it'll apply '>' to just about anything, even in strict mode), this is perhaps a stronger statement of intent: return Number.isInteger(x) && x > 0; Thus the more general assertion (is it an integer) guards the more specific specific one (is it greater than zero).

Another question is whether you'd want to include negative zero as a positive integer.

Re: NPM and Left-Pad: Have We Forgotten How to Program?

#768
post #577

Earlier quoted context omitted.

Discoverability happens with standardization. Why search through millions of unknown packages when a standard library would have it all right there?

Because the standard library is where modules go to die. Slaving the release cycle of a library to the release cycle of the language is bad for the health of that library, especially in the case of javascript where code often has to be written to run on old browsers with old versions of the standard library. Now having a metalibrary that depends on a curated collection of popular/useful utilities is probably a good i…

I've wondered why the official committee doesn't have a recommended list of libraries for specific purposes.

That way I can get a curated list of great functions I can trust.

Essentially a standard library for all intents and purposes.

Re: NPM and Left-Pad: Have We Forgotten How to Program?

#769

Earlier quoted context omitted.

Formerly 9 dependent modules... but who cares maybe it was a homework assignment or a joke. I don't use NPM so maybe it doesn't really matter aside from the level of abstraction being implemented being relatively ridiculous. However, if my build system had to go out and grab build files for every X number of basic functions I need to use, grab Y number of dependencies for those functions, run X * Y number of tests fo…

> I don't use NPM so maybe it doesn't really matter aside from the level of abstraction being implemented being relatively ridiculous. Except, again, it's no more ridiculous than pick a random bit of code from anywhere and isn't any more emblematic than that random bit because, again, it's not used anywhere. > [Quick Edit] Basically I'm saying "Get off my lawn ya kids!" tl;dr: going for buzzfeed headlines but for com…

Trying to keep the conversation light-hearted with a closing joke is more like it since everybody takes these things so seriously-- sorry I pissed in your cheerios good chap!

Re: NPM and Left-Pad: Have We Forgotten How to Program?

#770

Earlier quoted context omitted.

HN isn't: your browser is. Runs of whitespace are collapsed in HTML to single spaces unless specifically styled otherwise. You can verify that they're there by viewing the page source.

I like to use non-breaking spaces for that kind of thing, although they still might collapse that? At least it doesn't wrap non-breaking spaces.

No, they wouldn't collapse that: non-breaking spaces aren't considered whitespace in HTML. The side effect of that is that if you copy some text with non-breaking spaces, you'll get non-breaking spaces, so something that looks as if it contains spaces won't necessarily behave as such. In HN, if you need to quote something where space is significant, you're best off formatting it as a preformatted block by indenting it:

    Here is    some    preformatted text.
It might break up the flow of the text, but if something like whitespace is significant, that's probably a good thing.
Post reply on HN