by pier25 · 7y ago · 0 comments
The JS ecosystem is pretty fragile because every project depends on hundreds of other projects.
The other day I had to go back to a 2 year old Vue project. I found that many of the dependencies had vulnerabilities so I started updating those. Then nothing worked because the newer versions changed its API or didn't support such and such feature. In the end I had to reconfigure all the project from scratch. And this project was just 2 years old...
If you hadn't used those libraries, you would have had to implement functionality from those libraries in your own code. Presumably, your code would be subject to the same vulnerabilities and probably require even more work to update. After all, API changes are generally easier to handle than design changes.
</advocacy>
I do agree that tiny, insignificant libraries like "left-pad" are bad. Imo, a good dependency is one that significantly reduces the design complexity of a project.
There are universal utility libraries. jQuery for DOM, underscore for general utilities. It's OK to use them, because everyone knows them. But if you miss some tiny function, just write it yourself. DRY principle often brings more harm than good.
Same, but it's nice if those libraries have zero dependencies so when you include them in your project you know exactly what you're getting.
I must admit I have the same aversion as OC. I love the ubiquity, resources and portability of JavaScript, but the rats nest of dependencies feels extremely brittle.
- have few dependencies
- favor dependencies that, themselves, have few dependencies
- favor dependencies that have a single purpose
- favor well-understood stable libraries
- favor libraries that handle breaking changes well. A good Java example is commons-lang 2 vs 3 where the package name was changed so they can coexist. A bad example is Guava.
There is no need for the library ecosystem and dependency culture around a popular programming language to be as fragile as JavaScript's. Other popular programming languages manage not to have this problem to anything like the same degree.
https://www.theregister.co.uk/2019/03/28/hcsec_huawei_oversi...
Another thing is people either:
1. Use their own boring abstraction every time, and every abstraction might be different. 2. Not using abstraction at all, this makes JavaScript more like C code base.
Of course, I'm not saying it's not fragile now. But probably the answer is not as simple as dependency free. Some dialect provides interfaces (like TypeScript), type-classes (yet to be seen in mainstream dialects but I believe this really helps when dealing with fragility because Java could also be fragile because of nominal typing without having type-class) might help in the future.
1. usually a library has a wider range of features than you need. So you don't have to rewrite the whole library, just the bits you need, and you end up writing much less code because don't have to integrate the bits you need with the bits you don't need.
2. you do have to spend a lot of time understanding the interface of the imported library and writing integration code to use it correctly.
3. (as others have said) there's a lot of time spent auditing the library (and all its dependencies) to make sure it's not doing bad things. And that auditing work needs to be repeated every time any dependency of the library updates a version. This is especially important if you're doing anything with customer information involved - you're liable if you import a library that imports a dependency that quietly sends your customer's personal information to a url in Russia.
4. you may have to make architectural compromises to fit the library in; it might not support concurrent access, or idempotent calls, and that may cause more time loss in the long run than just writing what you need yourself.
5. the library becomes a black box, and your code becomes plumbing connecting the black boxes together. Trying to debug your application, or improve performance, or make it more robust, is impossible because you can't change any of the black boxes and your plumbing code does nothing important.
that's most of why I prefer to roll my own code rather than import a dependency in most cases (crypto being the notable exception).
In general; many deps is a bad idea for longevity of software. How can you know if it does not all crash and burn if the author changes jobs? Personally I want to know I have the sources and understand them enough to be able to support them with our team; in reality, for the JS ecosystem, that often means it is less work (those hours you mention) to write it yourself because it was trivial to begin with anyway and the npm solution has 1000 dependencies yours does not (for instance, they use deps like left-pad to implement something that can be implemented in 100 lines of pure JS, now needing still 100 lines but of rancid (unsupported?) one liner ‘libraries’ which is absolutely insane)
Managers usually are not programmers nor have technical background: once something works, they might not allocate time for you/your team to touch it for many years. You probably left or enjoying your pension (many anecdotes about that: a lot of companies are running on software that was done by one employee and he retired, years ago), while some poor junior who does not know what JS is, is holding your turd. At least with 20 year old PHP it still runs and without knowing PHP beforehand, it is not hard to change/fix for a capable programmer.
I have seen this with larger node.js and with Rails projects; not so much with Java and .NET projects; the latter seem to be fine many year later (maybe with some tiny migrations), even when updating libraries or runtimes.
It is a compromise ofcourse; I am not against reuse, but only to the limit we could possibly handle maintenance and updates ourselves of all imported libs. Otherwise it is a no-go.
many of these only work when installed globally and conflict each other version to the point the only way to work at project of different ages are chroots or flat out vms. whomever ever thought that -g was a good idea should never work at a tooling system again.
heck, some years ago you could push a library change to npm updating a version number that already existed there, the place is a mad house.
Sure, but a lot less time that planning, programming, debugging, maintaining your own library.
> In general; many deps is a bad idea for longevity of software. How can you know if it does not all crash and burn if the author changes jobs?
Many many times if a library doesn't work there are about 100 other ones that do the same thing.
> At least with 20 year old PHP it still runs and without knowing PHP beforehand, it is not hard to change/fix for a capable programmer.
How does it run? It's not even maintained anymore nor installable in any modern server. You can run it, and be exposed to all kinds of security holes.
> It is a compromise ofcourse; I am not against reuse, but only to the limit we could possibly handle maintenance and updates ourselves of all imported libs. Otherwise it is a no-go.
There's a much higher change of a single developer falling out of love/not having time for a project anymore than a major library becoming unmaintained or having a serious bug unfixed.
If that happens, you just swap it with another one. It takes 1/100th of the time compared to do everything yourself.