News for hackers. Stuff that matters.
Re:NPM package 'isarray' is downloaded 40M times a week by axiosgunnar on Sunday November 08, 2020 @10:31AM (#25026332)
You can think of these NPM micropackages as Github Gist snippets that you can programmatically link to your code.

The first advantage to just copy-pasting is that the snippet author might update it (e.g. if he finds a faster/safer way to do the one thing his package does), and you don't have to do anything.

Imagine finding a solution on Stackoverflow and just being able to import foo from stackoverflow/a/12345, and when the community finds a better way to do it, your software is automatically using the new version!

The second advantage is that it's basically built-in refactoring: Code from these micropackages will not litter your code, there is a clean separation between what is your business logic vs where you just need some generic functionality.

Re:NPM package 'isarray' is downloaded 40M times a week by Nursie on Sunday November 08, 2020 @10:38AM (#25026394)
> Imagine finding a solution on Stackoverflow and just being able to import foo from stackoverflow/a/12345, and when the community finds a better way to do it, your software is automatically using the new version!

That sounds like a security nightmare, and broken functionality waiting to happen.

How on earth have we got here?

Re:NPM package 'isarray' is downloaded 40M times a week by jka on Sunday November 08, 2020 @02:31PM (#25028236)
There are issues with micropackaging functions and code, and the fact that they didn't exist as a concept when the JavaScript language was being designed may contribute to that - but I don't think that it's clear whether micropackaging will turn out to be a good or bad trend overall.

Hundreds of thousands of untested, unaudited implementations of a roughly-similar function _could_ be far worse in terms of overall ecosystem stability and security than a small number of frequently-used (albeit yes, potentially flawed and vulnerable) micropackage dependencies.

The outcome for each micropackage may depend on how much scrutiny and test coverage is available when updates occur, and how well-defined the package's API is.

In a sense, that's not hugely different to version upgrades for other, larger library dependencies. Incremental library changes tend to be easier for developers to audit and integrate, so perhaps eventually this is a better approach?

In my opinion Microsoft (via GitHub and NPM) are likely best-placed to make significant progress on evaluating and improving the situation.

When a micropackage is updated, they're in a position where they could run continuous integration tests not just for the package itself, but also for dependent packages, to gain an early sense for the correctness and disruption potential of the change.

That kind of information would be useful to make a micropackaging ecosystem more viable and healthy, although it would also increase the ecosystem's long-term dependence on Microsoft.

Re:NPM package 'isarray' is downloaded 40M times a week by Nursie on Sunday November 08, 2020 @08:29PM (#25030599)
There is a middle ground between hundreds of thousands of untested, unaudited implementations of a roughly-similar functions, and packages which auto update without the developer doing anything at all.

At the least you want some oversight when a dependency changes under you.

Re:NPM package 'isarray' is downloaded 40M times a week by jka on Monday November 09, 2020 @11:26AM (#25036413)
Yep, pinning specific package versions should probably be a more commonplace practice than it currently is.
Re:NPM package 'isarray' is downloaded 40M times a week by izgzhen on Monday November 09, 2020 @03:40AM (#25032656)
As someone studying programming languages I used to be shocked by such practice as well — but later on I realized that, for people doing this, they really don’t have any practical motivation to care much beyond getting it to work first for immediate business needs.

Similarly, many more “principled” programmers don’t really understand many parts of our computing stack either and it did bring troubles to even the most experienced veterans in the industry.

It is always a trade-off between risk, cost, and benefit.

Re:NPM package 'isarray' is downloaded 40M times a week by dzhiurgis on Sunday November 08, 2020 @04:41PM (#25029342)
Hardcode the version and it will never update.

Otherwise you can (and should) review the update manually or using automated tools.

Re:NPM package 'isarray' is downloaded 40M times a week by toomuchtodo on Sunday November 08, 2020 @10:57AM (#25026555)
Abstractions over expertise and effort, driven by expectations outside of the practitioner’s control.
Re:NPM package 'isarray' is downloaded 40M times a week by jen20 on Sunday November 08, 2020 @10:34AM (#25026354)
> The first advantage to just copy-pasting is that the snippet author might update it

The first disadvantage of “micro packages” over copy-pasting is that the author might update it to do something completely different - either because the author is malicious, or because of a transfer in maintainership of the package to someone who is malicious, or because of a compromise.

Re:NPM package 'isarray' is downloaded 40M times a week by usefulcat on Sunday November 08, 2020 @10:59AM (#25026569)
Or even without any malicious intent, simply because the functionality provided by the package is under/poorly specified.
Re:NPM package 'isarray' is downloaded 40M times a week by ceceron on Sunday November 08, 2020 @11:24AM (#25026754)
> The first advantage to just copy-pasting is that the snippet author might update it (e.g. if he finds a faster/safer way to do the one thing his package does), and you don't have to do anything.

First, please don't copy paste solutions. Understand them and implement correctly. Stackoverflow is not a magic library you should take books from without understanding.

> Imagine finding a solution on Stackoverflow and just being able to import foo from stackoverflow/a/12345, and when the community finds a better way to do it, your software is automatically using the new version!

Wow, I've just imagined it. Props for the great horror story, but... it's a security nightmare. You basically surrender all control over your project for almost nothing.

> The second advantage is that it's basically built-in refactoring: Code from these micropackages will not litter your code, there is a clean separation between what is your business logic vs where you just need some generic functionality.

Writing this utility in a separate code unit (namespace, project, whatever) gives exactly the same advantage. And micropackages will litter my building process / dependency tree.

Re:NPM package 'isarray' is downloaded 40M times a week by marcus_holmes on Sunday November 08, 2020 @10:44AM (#25026438)
That would be true if it was "the community". But it's not. It's one person. So you're literally giving Julian Gruber commit access to your production environment in the hope that he finds a better way of doing something that is a polyfill for something that browsers now do better.

I don't understand how that is a rational decision that people are making. Can anyone explain?

Re:NPM package 'isarray' is downloaded 40M times a week by spicybright on Sunday November 08, 2020 @10:36AM (#25026373)
The downside is, your code and your heavier libraries now have their dependencies changing constantly, which can lead to things breaking if either depend on specific behavior, or if the micro package author does something wrong.

It's a trade off, although personally I've been bit by that enough to keep strict version numbers in my dependencies.

Re:NPM package 'isarray' is downloaded 40M times a week by vbezhenar on Sunday November 08, 2020 @10:36AM (#25026370)
> Imagine finding a solution on Stackoverflow and just being able to import foo from stackoverflow/a/12345, and when the community finds a better way to do it, your software is automatically using the new version!

What a nightmare!

Re:NPM package 'isarray' is downloaded 40M times a week by tyingq on Sunday November 08, 2020 @10:40AM (#25026410)
"if he finds a faster/safer way to do the one thing his package does"

That seems to have happened here, though who knows across X number of browsers and whatever JS engine updates happen.

https://github.com/juliangruber/isarray/commit/1052c9d94dc87...