This is an anonymous question sent in by a member who does not want their name disclosed. Please be thoughtful with your responses, as these are usually tough posts to write. Email sloan@dev.to if you'd like to leave an anonymous comment or if you want to ask your own anonymous question.
For further actions, you may consider blocking this person and/or reporting abuse
Top comments (7)
A standard library is a bunch of functions and types that are pretty much always included with a specific programming language. That is, if you're programming in the language, you can safely expect those things to be available to you.
This is different from actual features of the programming language. Adding numbers together with a plus sign
1 + 1
is not part of the standard library. But if you're programming in Python you'll have access toabs()
, a function for getting the absolute value of a number, which is part of the standard library.What's the difference? Technically
abs()
is not a unique or essential piece of Python syntax so you could create a Python implementation that doesn't have it. You'd get a bunch of angry programmers in your inbox, but it would still be Python! But if you created a Python implementation without the plus sign+
infix operator, it wouldn't be Python at all.The Python standard library is documented here. The JavaScript standard library, here. You can google "{language} standard library" to find documentation for whatever language you're working in.
Others have provided good answers, but I'd like to expand on them a bit.
In C on Linux there are a couple of functions,
mmap
andmalloc
, which are used to claim exclusive access to some memory. (mmap
has another use that it's more known for, but that's beside this point.) Both of these are part of what we might call the Linux standard library for C:mmap
is in mman.h, andmalloc
is in stdlib.h.C++, on the other hand, has a language keyword called
new
. For all intents and purposes,new
andmalloc
do the same thing, butnew
is part of the language itself rather than coming in from a standard library.Similarly, the C standard libraries have no real support for arrays that change size over their life—you can absolutely do this in C, but you have to do everything by hand. The C++ standard libraries provide a variety of automatically resizable collections, in the Standard Template Library.
I said all this to illustrate a point, which is... What ends up as language features, keywords and block structures and the like, is a series of decisions driven by the goals of the language designer. Typically one tries to keep the language features as minimal as possible while still being able to do what the language is supposed to do. C++ needs
new
to be a language feature because object instantiation is core to what C++ is. C does not neednew
because its type system is simpler than that.What ends up in standard libraries is more like, a guess on the part of the language designers as to what users will need to be effective in the language. Nowadays this tends to include math (as Isaac pointed out), collections, memory management, string manipulation, network traffic, and on and on.
Anything you don’t have to npm install
Right, and Node and browser JS have different standard libraries, even though (for example) both Node and Chrome use Google's V8 engine.
There are features, classes, objects and functions that both have. But Node has some specifically for server-side operations (e.g. working with a filesystem and listening for network activity), and JS in a browser has some specific to web (e.g. for the DOM and browser window).
Lol I was trying to keep it simple.
Yeah, I realized after I posted that that it defeats the purpose of "explain like I'm five". 🤦♂️
Here is my attempt: A set of common (frequently used) functionalities curated by creators of the programming language, so you don't have to write from scratch