Live data from Hacker News

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

haneycodes.net

381–390 of 887 posts

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

#381

Earlier quoted context omitted.

reduce isn't a safe way to add floating-point numbers unless your accumulator is much more precise than your array values. You'll end up with what they call "catastrophic cancellation". And they won't let you have fixed-point in JavaScript!

Doesn't a for loop have the same problem?

If you write the loop yourself, you can add everything to a double instead of a float, or a long double instead of a double, if you have those.

Oh, if all your numbers are positive you can also sort the array and it will minimize the error accumulated, but I'm not sure what to do with mixed signs.

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

#383
post #7

Holy moly-- is-positive-integer/index.js: var passAll = require('101/pass-all') var isPositive = require('is-positive') var isInteger = require('is-integer') module.exports = passAll(isPositive, isInteger) I retract my previous statements that Javascript programmers are going down the same enterprise-y mess that Java programmers went down a decade ago. They've already taken it to an entirely different level of insani…

Yeah, I thought the dependency thing was a joke (I mean, to have a package for is positive integer is already a joke, but come on) Really

Yea. I don't think many argue against abstracting complexity into more easily understood orthogonal modules. But some of these modules aren't abstracting complexity. They are ludicrous. They are nonsense. They are a symptom of a very real problem with how JS is programmed, how people expect to program in JS, and the difficulty people have with decomposing problems.

So many people on this page have written about how these are well tested, performant, and correct modules. But, the modules aren't even correct in many cases, let alone providing incomplete coverage over edge cases or the slow performance and horrendous dependencies of many of the modules.

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

#384

Earlier quoted context omitted.

They do NOT encourage code re-use because the effort required to understand your need, refrain from writing code, and hunt down a module in npm, far outweighs the effort to just write the code and stick it in your in-house utils library.

Yeah but, why do you need your own in-house utils library. Node needs batteries included!

Because writing code is what programmers (should) do. If something is simple, then it is simple and won't take up time and energy. If you don't know how to do it, then learning how to do it is worthwhile -- especially if it turns out to be simple. If you make a mistake, then someone on the team must look at the code and understand the mistake. This means that the team learns that things that seem simple are sometimes complex and they learn how to recognise their mistakes. When there is a mistake, someone has to fix that mistake. They learn how to fix the problem. Other people on the team must review that fix and they also learn how to fix the problem.

There is always a balance between getting some extra productivity by using somebody else's code, or getting the knowledge, expertise and control of writing it yourself. Far too often I see young programmer's choose something off the shelf so that they don't have to understand it. This is a recipe for disaster -- for your project, for your team and for yourself.

IMHO, as programmers, we should err on the side of writing code. Often it is obvious that you should use standard libraries, or a particular framework or or another reuse library. But where it is not really obvious, I would start with writing your own code and see where it gets you. You can always replace it later if it doesn't work out. I think you will find that you and your team will be miles ahead if you take this approach.

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

#385
post #154

Earlier quoted context omitted.

Sounds like the author was aiming for something to put on his resume: e.g., "Author of 25 libraries on NPM, some with more than 500K downloads." etc...

Well if I was interviewing the guy, my second or third question would be "tell me about these packages you published on NPM" It's going to be damn hard to make an average function sound impressive.

I think you're seriously overestimating quality of the average programmer candidate.

Someone who understands what NPM is, has written and published working code (even stupid code) is miles ahead of the curve already.

Most companies in the world, especially non-software companies, don't go for 5% hacker gurus. Attracting someone vaguely competent is already a blessing.

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

#386
post #303
post #277

Earlier quoted context omitted.

> I do expect to be able to call "average" on a list of numbers without writing it myself Just out of interest, what kinds of functions would you expect to have to write yourself, if you're not happy about calculating the average of a list of numbers?

Alright, take a simple function like average. How might someone naively calculate the average? for n in list sum += n return sum / len(list) Which will fail but will probably be caught in the code review. Then a cleverer developer might think to write l = len(list) for n in list sum += n / l return sum Which will also fail but in more subtle ways, hopefully the senior dev will catch it in the code review. Then they c…

No reason to turn something trivial into rocket science.

You examples does not mention the type of variables involved. And dependent on the type and the language your first example may be (a lot more) correct compared to your third example. Ie. negative floating point numbers.

But who says that a library implementation is a lot better than what you as a programmer can come up with?

In particular with all these "micro" libraries written by random people.

Are they actually smarter than you? Do they understand the "edge" cases as you do?

Most people don't bother with looking at the library source code they are importing. And I don't blame them because things are in general a mess and not only for JavaScript.

The solution, for me at least, is to import less and be more conversative with what you import.

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

#387
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.

Yes, but it's MIT licensed. We also need average_GPL to go with it.

You bring up a good point with respect to copyright/licensing --- at what point does code stop being copyrightable and become public domain simply due to pure triviality? There are not very many sane ways to write an averaging function, and the most straightforward one (add up all the value, then divide) would probably be present in tons of other codebases.

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

#388
post #377
post #279

Earlier quoted context omitted.

Can we ever achieve this? We can't exactly search the code to find out what it does, otherwise you'd basically be reading all the code to discover it's true behavior, which negates the usefulness of modules in the first place... Any search will have to rely on developer-made documentation, and/or meta data. This is great in theory, but documentation is rarely well maintained, and/or someone changes the code but negle…

We could have something similar with full dependent types a la Idris: you could write a proof and search for a function that satisfies it. If such a thing were popular and huge amounts of Idris code were written, you could write only proofs for your program and the Idris system could go download and piece together your program! That would be very cool, but I'm not sure how much easier it would actually turn out to be…

Similar idea but what if you were to write your tests first and then upload them to a site that pieces together the required modules to pass them and generates an API against the modules.

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

#389

Earlier quoted context omitted.

No, no, no Left padding is (almost in all languages) built-in, even C can do it with printf (edited) The problem is not having a library that offers that, but having this micro-module thing as a whole NPM module . No other language does that. If it was inside a string helpers, that's great. But don't make me one single module for just left-padding (or is-integer-number)

Uh, no Left Padding is NOT built-in in JavaScript. The proposal to add `String.prototype.padLeft()` was just added to ECMAScript 2016. JavaScript had a very minimal standard library, it's pretty asinine of you to compare it to C or any other language with a pretty extensive standard library.

C didn't get a standard (or a standard library) until 1989. It had been around for 17 years at that point. Two years after its invention, JavaScript was standardized in 1997. That's almost twenty years ago.

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

#390

Earlier quoted context omitted.

You'd have a good point, if all of those tiny but probably useful modules were given the use you're describing. Discoverability though is so poor that most of those modules are most likely just used by the author and the author's co-workers. If a typical npm user writes hundreds of packages, how the hell am I supposed to make use of them, when I can't even find them? Npm's search is horrendous, and is far from useful…

The isArray package has 72 dependent NPM packages, it's certainly not undiscoverable. The leftpad package gets 5000 downloads a month, that's quite a bit of testing for edge cases, compared to the none that I would have gotten had I implemented this myself. Intuitively, this thread wouldn't exist if your assertion were correct.

And when a bug is found, instead of fixing it in one place once, you now have to hope that all of your deps and all of their deps update themselves appropriately.
Post reply on HN