Live data from Hacker News

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

haneycodes.net

581–590 of 887 posts

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

#581
post #279

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…

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…

> 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 neglects to update the documentation.

This is why types are better than textual documentation - the system enforces that they're kept up to date.

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

#582

Earlier quoted context omitted.

There are definitely trade-offs involved when making decisions to inline vs import. Strictly speaking, you're definitely right. Each dependency is an additional point of failure, but so is each additional line of code you inline . The benefits of these small modules is that they're very thoroughly tested by the entire community. I'd say for most cases, they will be much more robust than any solution an individual dev…

> There are definitely trade-offs involved when making decisions to inline vs import. If someone can't make the right trade-off regarding "should I import a module called "isArray" or "is-positive-integer", then they should not be programming...

Yep. Everyone mocking NPM and the javascript community for this ought to retire, they clearly don't understand how to program in this day and age. Or is that not what you meant?

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

#583
post #566

Earlier quoted context omitted.

Do you seriously think that "word starts with a capital letter" is an easy function to write? I feel like you haven't spent enough time with Unicode.

return string[0] === string[0].toUpperCase(); You're welcome!

Not that I agree with micro modules (I would rather see a set of js core libs), but your code fails with empty strings.

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

#584
After reading this, i don’t think i’m capable of ever complain about OOP again. Whenever you think you’ve seen it all, web developers always manage to come up with something worse. The only thing more depressing than this is the comment section below the article.

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

#585
post #562

Earlier quoted context omitted.

I think the gist of this whole discussion ( at least the OMG WHY?!?! ) part, can be easily explained by an excerpt from your example comment that sums up in a nutshell the all too pervasive mindset I've seen over the years: "...LOC is pretty much irrelevant. It doesn't matter if the module is one line or hundreds. It's all about containing complexity. Think of node modules as lego blocks. You don't necessarily care a…

Promise was clearly necessary, because without it we had hundreds of other less principled ways to implement async control flow :)

We had, and still prefer (looking at npm stats) the async module. Eg:

    promise.then(function(){}).then(function(){}) 
is not substantially different than:

    async.waterfall([function(){}, function(){}])
Promise advocates kept pretending async didn't exist though, and everybody was using callback hell.

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

#586
post #583
post #566

Earlier quoted context omitted.

return string[0] === string[0].toUpperCase(); You're welcome!

Not that I agree with micro modules (I would rather see a set of js core libs), but your code fails with empty strings.

That code fails in a whole host of cases, kind of proving that sometimes trivial "just one line" functions aren't actual that trivial to get right.

edit: fortunately there's an npm modules you can included to fix it...

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

#587
Its interesting how everyone used this as a chance to attack the small modules approach. This approach definitely has downsides, but the problem caused by leftPad being unpublished wasn't one of them.

If jdalton declared a jihad on arrays tomorrow and decided to pull all array related functions from lodash, we would have the exact same problem.

If kriskowal decided that Q must mirror built in Promise and published a version that does this tomorrow, we would again have the exact same problem.

There is only one connection between this problem and the small module approach. As the size of a module decreases, the number of dependencies increases and so does the number of authors that produced your dependencies. With the number of authors increasing, the chances that some author decides to go rouge or protest for some reason also significantly increases.

Therefore, its irresponsible to use this approach with a package manager that allows an old, established module with many dependents to be unpublished so easily by the original author.

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

#588
post #6

I don't see anything wrong with using a pre-made left pad function. Why waste time and lines of code implementing something so trivial when there is already a solution available? However, I agree it is ridiculous to have a dedicated module for that one function. For most nontrivial projects I just include lodash, which contains tons and tons of handy utility functions that save time and provide efficient, fast implem…

Every function in Lodash is also available as a dedicated module, for the same reason left-pad existed: https://www.npmjs.com/package/lodash.padstart

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

#589

Earlier quoted context omitted.

And WebAssembly means that soon it will be practical to use any language on the client or server side.

It already is on the server-side. Feel free to use C; at least it would be performant.

It's easy to write code that does the wrong thing quickly in any language, and IME that tends to be the usual result of choosing C.

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

#590
post #571

Earlier quoted context omitted.

> This GitHub comment by Sindre Sorhus (author of over 600 modules on npm) is my favorite writeup on the topic: https://github.com/sindresorhus/ama/issues/10#issuecomment-1... . If anything looking at sindresorhus's activity feed: ( https://github.com/sindresorhus ) perfectly supports the author's point. Maybe some people have so little to do that they can author or find a relevant package for every single ~10 line f…

> Maybe some people have so little to do that they can author or find a relevant package for every single ~10 line function they need to use in their code and then spend countless commits bumping project-versions and updating package.json files. I have no idea how they get work done though... Rather than copy paste someone else's unmaintained thing and handle all the bugs, or write their own code and unit tests, they…

If you don't know how to write a function to left-pad a string without copy & pasting, you have other problems..
Post reply on HN