Live data from Hacker News

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

haneycodes.net

171–180 of 887 posts

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

#171

Earlier quoted context omitted.

You can't escape problems by bundling specific library versions. You just get a different set of problems. When you require a specific version of a library, you're making your code incompatible with anything that requires a higher or lower version of that library. You're also assuming there will never be a security fix that requires you to update your dependency.

...you're making your code incompatible with anything that requires a higher or lower version of that library. Actually that's not correct when using node/npm (or anything else in the ecosystem like browserify). That is one of the impressive things about this platform: any number of different versions of the same module can be required by the same app. It would be nuts to do that in your own code, but as long as the…

...and now you can have all the bugs introduced in all the versions of the library! Yay!

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

#172

Earlier quoted context omitted.

Do you support IE 8? If not, why not use the one provided by the language, Array.isArray() ?

The latest version of lodash (4.0.0) doesn't support IE 8, so you would need to polyfill isArray() yourself or use a pre-modern lodash version.

Yeah I agree that polyfilling makes more sense than depending on lodash just to get isArray(). I wonder if we'll start seeing the sorts of "you don't need..." rants about lodash that we've seen about jquery for some time now?

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

#173
post #88

We have. I spent some time optimizing [0] a String.repeat function over at Stackoverflow and I was surprised that many developers today don't know what they are doing, including core team members [1]. Specifically, function repeatString(str, len) { return Array.apply(null, { length: len + 1 }).join(str).slice(0, len) } [0]: http://stackoverflow.com/questions/202605/repeat-string-java... [1]: http://stackoverflow.com/…

[deleted]

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

#174
Here's a proposal (that I'm sure others have come up with in the past) -- why not create one big, community backed "batteries included"-type module that would implement all the small, commonly used functions. This could combine all these ridiculously small libraries and greatly reduce the number of necessary dependencies for a package. Extending the standard library should be just that: standardized. If the entire community focused on one project like that they could just as easily write the same code (but with smaller package.jsons, less require()s, and less time spent learning new libraries/searching for the right libraries. In fact, it would be great if something like that could be packaged as a standard node module so you'd get the same sort of quality assurance as you get with official projects.

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

#175
I call this kind of attitude the "Tea Party" of JavaScript development. The reason why we currently have JavaScript tooling fatigue is exactly because Tea Party developers insist on writing everything themselves instead of trying to build a better abstraction. The lesson here isn't not fewer dependencies: it's managing dependencies. NPM should not allow someone to arbitrarily remove modules that other's may be depending on. It's like building a bridge and them deciding to remove it after a whole city now depends on it.

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

#176
post #58

Earlier quoted context omitted.

Similarly, the `average` package on NPM is one that I came across: https://www.npmjs.com/package/average var average = require('average'); var result = average([2, 5, 0, 1, 25, 7, 3, 0, 0, 10]); console.log('The average for all the values is:', result); It's hard to not stare at that in complete disbelief; someone thought that it was worthwhile to create a package for determining the mean of an array of numbers.

You know what's worse? Javascript numbers are all floating point numbers, which means integers are 53 bits long. So, you might think this library would try to address issues this can cause, but nope, this is the average statement you'd write if you didn't know was a mantissa was and had never heard of big.js, bignumber.js, decimal.js, crunch.js or even strint (which represents integers as strings because wtf not).

Not to mention the fact that adding many floating point numbers in a naive way results in a serious error accumulation, which is why things like Kahan summation algorithm[1] exist.

[1] - https://en.wikipedia.org/wiki/Kahan_summation_algorithm

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

#177
post #28

Everything in this article is categorically wrong and antithetical to every principle of good programming ever articulated. The only problem here, as others have already noted, is that NPM allows people to delete published packages. Small modules are not evidence of a problem, and they certainly aren't evidence of an inability to implement these things on the part of the people depending on them. Why would I implemen…

> Why would I implement left-pad myself when there is already a well-tested implementation that I can install? You call 4 basic assertions "well-tested"? https://github.com/azer/left-pad/blob/master/test.js

a) I think that's a fine number of tests for a module this simple, which is itself an argument in favor of small modules. And I think it's four more assertions than anyone implementing this inline in a project would have.

b) The details of this particular project are orthogonal to the philosophy of small modules generally. Whether or not this module is well implemented or well tested has no real relation to whether or not it is a good idea to compose tiny modules.

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

#178

Earlier quoted context omitted.

...and then the publisher pulls their library off npm, and another shows up and drops one of the same name in its place, with compatible version numbers (by happenstance or otherwise).

A version can't be republished.

True, but it's common to have requirements of the form "^1.0.0" (especially since this is the default of npm i --save). It's easy to publish a new version that would be installed by a project declaring a dependency in this form.
Post reply on HN