Hacker News new | ask | show | jobs
by KaiserPro 669 days ago
I suspect this might be seen as trolling, but why isn't there a standard lib of stuff like this?

surely it can't be beyond the wit of programming kind to have a standard lib, or even layers of standard lib for Node?

What is the argument for not having a standard lib, apart from download speed?

4 comments

I'm not taking an absolute position either way -- the devil is in the details -- but here's my steelman for the opposing view:

When you put something in the standard library, it's harder to take it out, meaning that you're committing development resources to support the implementation. Furthermore things change: protocols and formats rise and fall in popularity and programming style evolves as the language changes (e.g. callbacks vs. promises in JS). Therefore the stdlib becomes where libraries go to die, and you'll always have a set of third party libraries that are "pseudo-standard", like NumPy in Python.

Having a minimal stdlib lets you "free-market" the decision, letting the community effects take care of what is considered standard in the ecosystem, and lets you optimize its minimal surface, like what happened with C.

But people don’t have to spend social capital to get it used at the next place they work.
Why isn't there some kind of 'compiler/linker/stripper' that would collect the functions actually used and compile them into an application specific library? Yes I know that dynamic dispatch makes that difficult but the programmer does surely know which functions he wants to call.

I sometimes hanker for a return to Fortran IV where every routine was separately compiled and the linker only put into the object code those that were referred to by something else.

Do you mean tree-shaking? I think basically all JavaScript "compilers" do this these days so that the code you serve is only the code you actually use.
Zig handles this with lazy compilation: code is parsed, but not even type checked, until the compiler reaches it.

This can lead to the occasional rude surprise when finally reaching code I've been working on for awhile, but haven't yet connected to the rest of the project. But it means there's no need for tree shaking, because nothing gets in until it gets used. One of my favorite things about the language.

its such a useful technique. tiny binaries ftw!!
There are many ways to look at this. Maybe the standard lib of such functions should be implemented as native functions in the language (1). Or as a standard external function library (2). Or people should copy-paste the functions they need and keep in their organization's function library (3). I am sure there are a few more options.

I moved to option 3: in all my apps I include a function library that I build over the years, so I don't start from scratch every time. I deeply hate ("hate speech" example here) dependencies to libraries from all over the Internet due to security reasons, but I copy-paste code when needed to my library after I read, understand and check the code that I copy. The biggest advantage is that some of this code is better than what I could invent from scratch in a busy day and I save the time of doing it right. The disadvantage is there is no way to reward these authors that contribute to humankind.

PS. My function library has functions mostly written by me, over 80%, but it includes code written by others. In my case, every time I need a function I check my existing library first, then analyze whether to write or copy.

I assume you correctly obey the licensing when you copy and paste it in....
Yes. It is not worth not doing it.
Every non-trivial Java project I've worked on ends up depending on Google's Guava and some combination of Apache Commons libraries.