Standard Library
- Summary
-
Discussion
- What should a standard library typically include?
- What are some advantages of using a standard library?
- How are standard libraries delivered or distributed?
- Who should read standard libraries?
- What are some considerations when defining a standard library?
- Should a standard library be exhaustive or minimal?
- Could you list some examples of standard libraries?
- What happens if commonly required functions are not part of a standard library?
- Are there well-defined processes to evolve the standard libraries?
- Milestones
- References
- Further Reading
- Article Stats
- Cite As
Every programming language defines a basic set of components that can be reused by programs. Every implementation of the language should provide these components. This set of reusable components is what we call a standard library.
A good standard library is essential to the long-term success of a programming language. However, there's no consensus on what or how much should be included in a language's standard library. Python and Java have large standard libraries while C takes a minimalistic approach.
The definition of a standard library is not limited to languages. It can be extended, for example, to frameworks. Thus, we can say that Django (web framework) and Robot Framework (test automation framework) have their own standard libraries that are installed by default with the framework.
Discussion
-
What should a standard library typically include? Since the C standard library is minimal, it gives us an idea of what's typically included. These are either macro constants or functions. In an object-oriented language such as C++, classes, class templates and methods are part of the standard library. Others (Java, PHP) may additionally include interfaces.
Operations that are deemed necessary for most programs are included. A standard library will have functions to access the file system and perform input/output operations; functions that deal with the data types of the language; functions that allow memory allocation and manipulation; functions that enable multithreaded programming; functions to handle date and time; common math functions; functions for error handling and assertions.
Modern languages have lot more than what C standard library offers. C++ has classes for containers, algorithms and regular expressions. Python has packages for data persistence, data compression, cryptography, exception handling, networking, CSV/XML parsing, GUI, testing, profiling, and more.
-
What are some advantages of using a standard library? Developers can focus on their application logic rather than low-level details, which are provided by the standard library. Code can be reused across projects. Code is more maintainable since most developers will be familiar with the standard library. There's also a shorter learning curve for new developers joining a project.
Since implementations of the standard library are optimized and well tested, programs that use them are likely to be more reliable. If the language is open source, developers can also study the implementation of the standard library to learn best practices.
Projects that use the standard library might even be smaller since developers are not introducing custom code for some modules while using the standard library in others.
-
How are standard libraries delivered or distributed? A standard library is not simply one physical document but rather a combination of many things:
- Standards document: This is the main document released with every version of the language. This will include core parts of the language plus what's in its standard libraries. For example, C and C++ standards documents are released by ISO and must be purchased. In other languages, these may be more readily available online.
- Header files: This is typical of C and C++. Header files specify what's available in the standard libraries.
- Implementations: When a language compiler or interpreter is installed on a machine, an implementation of the standard library is also installed. In Python, users have a choice of different implementations of the standard library, with CPython being the default.
- Delivery: In C and C++, implementations are object files. In Python, they are packages containing modules. In Java, we have packages containing classes. In client-side JavaScript, implementation is built into the web browser.
Documentation and header files may also be termed as the Application Programming Interface (API) of the language. It's also common for vendors to include useful non-standard functions at the expense of portability.
-
Who should read standard libraries? There are a few types of folks who need to read them: compiler writers, those who implement standard libraries, tool vendors, and users of the standard libraries.
Standards documents are usually hard to read because they are formal, legal and highly detailed. They are meant for compiler writers and those who implement standard libraries. Tool vendors may also read them. For everyone else, it's usually sufficient to read the documentation on how to use the standard libraries in their code. Tutorials and example code showing the use of standard libraries are more useful than reading the language standards.
-
What are some considerations when defining a standard library? What a standard library provides should fulfil the needs of programmers. In 2016, when initiating a revision of C standard, convener David Keaton pointed out that security threats on the Internet are growing, Moore's Law is failing and there's a need to exploit concurrency and parallelism in programs. Languages must therefore evolve to address these new concerns.
Standard library must balance stability and evolution. Design should address safety, security, simplicity, interoperability, demanding application domains, and embedded systems. To add a feature, we must consider how it would interact with other features. Updates to the standard library must be backward compatible to earlier versions. While there could be some platform-dependent features, portability should be improved. Sometimes portability may be sacrificed for performance, at least in C.
One point of view is that most standard libraries lack features and they are incompatible across languages. What if you could write a library in one language and automatically translate it into any desired language? Loyc Multi-Language Standard Library (MLSL) aims to do this.
-
Should a standard library be exhaustive or minimal? C and C++ are minimal. Java provides many higher level utilities out of the box. While this benefits developers, it also bloats the language. Some APIs become antiquated and less useful, though they would have to be maintained unless deprecated. Python also adopts the "batteries included" approach and provides many sophisticated packages as part of the standard library. While this is useful, it also means that new implementations have more work to do. A small library implies that multiple implementations are possible and all programmers can rely on it.
There's been some debate about moving C++ towards a "batteries included" approach, such as adding a graphics library. Alternatively, C++ can be kept minimal while finding a better way to distribute libraries and dependencies.
The choice that language designers make must be governed by the its main purpose. Should it a general purpose language or satisfy a niche? It's been said,
No language can be everything for everybody.
-
Could you list some examples of standard libraries? Here's a short and non-exhaustive list of some standard libraries:
- C: assert, float, math, stdio, stdlib, string, threads
- C++: list, map, deque, vector, algorithm, iterator, string, regex, fstream, iostream, exception
- Python: list, dict, tuple, range, open, enum, collections, math, pickle, zlib, threading, queue, email, json
- Go: tar, gzip, heap, crypto, hash, image, io, mime, net, os, path, strings, time, unicode
- Java: java.lang, java.io, java.net, java.math, java.text, java.awt.image, java.security, java.beans
-
What happens if commonly required functions are not part of a standard library? There's nothing in C standard library to help a developer send emails from a C program. The developer is forced to build this feature from low-level networking constructs. Moreover, that code can't be reused by others since it's not part of the standard library.
This is where the power of the community becomes important. Useful functions that are not part of the standard library are curated, reviewed and shared via public repositories. In Java, there's Apache Commons. In Python, there's PyPI. For C++, Boost provides peer-review libraries, some of which were later accepted into the standard library. For C, there's POSIX standard library that enables portability across different variants of UNIX/Linux while adding many functions missing in C standard library.
C++ Boost binaries can be downloaded and installed for your platform. Modern languages implement the concept of package/dependency management. Software is gathered into centralized repositories and tools exist to manage packages and version dependencies as necessary for your project. Example repositories include Packagist (PHP), PyPI (Python), CPAN (perl), NPM (Node.js), and Maven (Java).
-
Are there well-defined processes to evolve the standard libraries? Languages that are proprietary (such as MATLAB or Wolfram) will have closed processes. Customers of these products may request features. Otherwise, they have little control on how the language or its standard library evolves. On the other hand, more open languages are standardized by a process that allows greater community participation.
Both C and C++ are standardized by the International Organization for Standardization (ISO). Meetings are organized regularly to discuss changes to the language. Participants are organized into working groups. Proposals are submitted and refined to produce working drafts. Voting by members will promote these drafts to becoming part of the standard library. Those who wish to make proposals, should study the Standard Library Guidelines.
In the case of Python, the Python Software Foundation (PSF) does regular releases. Any modification to the standard library is done via a Python Enhancement Proposal (PEP). Proposals are discussed and documented in draft stages. Once finalized, they're implemented.
Java has the Java Community Process (JCP) and proposals are managed as Java Specification Requests (JSRs). PHP has an RFC process with clear guidelines on how to participate.
Milestones
The ANSI C standard library is standardized to overcome compatibility problems across variations and implementations of the C language. Effort towards this important milestone started back in 1983 when the American National Standards Institute (ANSI) formed a committee. This standard is also called C89. Normative Addendum 1 (NA1) is added to it in 1995.
1999
References
- Barcellini, Flore, Françoise Détienne, Jean-Marie Burkhardt, and Warren Sack. 2005. "A study of online discussions in an Open-Source Software Community: Reconstructing thematic coherence and argumentation from quotation practices." Proceedings of the 2nd Communities and Technologies Conference. Accessed 2018-12-11.
- Behrens, Matt. 2014. "Chapter 16: django.contrib." The Django Book, commit 694e4a37, October 23. Accessed 2020-07-20.
- Blekhman, Alex. 2008. "What Every Computer Programmer Should Know About Windows API, CRT, and the Standard C++ Library." CodeProject, August 22. Accessed 2018-12-11.
- Boost. 2018a. "Boost: Homepage." Accessed 2018-12-11.
- Boost. 2018b. "Old Versions." Accessed 2018-12-11.
- Choi, Steve, and Pablo Ceballos. 2020. "Guide to C stdlib functions." CS107, Stanford University. Accessed 2020-07-20.
- Dawes, B., H. Hinnant, B. Stroustrup, D. Vandevoorde, and M. Wong. 2018. "Direction for ISO C++." Doc no. P0939r0, February 10. Accessed 2018-12-11.
- Everything Cpp. 2017. "C++ Standardization Process." YouTube, August 13. Accessed 2018-12-11.
- Ganesh, SG. 2007. "60 Tips On Object Oriented Programming." Tata McGraw-Hill Education.
- Golang. 2018. "Packages." Build version go1.11.2. Accessed 2018-12-11.
- Grimm, Rainer. 2017. "C++17 - What's New in the Library?" Modernes C++, April 3. Accessed 2018-12-11.
- ISO. 2012. "ISO/IEC 30170:2012: Information technology -- Programming languages -- Ruby." Edition 1, April. Accessed 2018-12-11.
- ISO CPP. 2018a. "The life of an ISO proposal: From “cool idea” to “international standard”." Standard C++ Foundation. Accessed 2018-12-11.
- ISO CPP. 2018b. "The Standard." Standard C++ Foundation.Accessed 2018-12-11.
- JCP. 2018. "Java Community Process: Homepage." Oracle Corporation. Accessed 2018-12-11.
- Jones, Christopher. 2013. "The Mysterious PHP RFC Process and How You Can Change the Web." Blog, Oracle, February 13. Accessed 2018-12-11.
- Keaton, David. 2016. "C - Preliminary C2x Charter." WG 14 N 2021, Open Standards, March 12. Accessed 2018-12-11.
- Loyc. 2014. "Design elements of a multi-language standard library." Loyc: Language conversion & interoperability, August 14. Accessed 2018-12-11.
- Python Docs. 2018a. "The Python Standard Library." v3.7.1, Python Software Foundation, December 07. Accessed 2018-12-11.
- Python Docs. 2018b. "The Python Tutorial." v3.7.1, Python Software Foundation, December 11. Accessed 2018-12-11.
- Reiz, Robert. 2015. "Which programming language has the best package manager?" VersionEye Blog, January 15. Accessed 2018-12-11.
- Robot Framework. 2020. "Robot Framework documentation." Robot Framework. Accessed 2020-07-20.
- Taylor, Kelsey. 2020. "PyPy vs. Cython: Difference Between The Two Explained." Blog, HiTechNectar. Accessed 2020-07-20.
- Wikibooks. 2018. "C Programming/Standard libraries." Wikibooks, April 4. Accessed 2018-12-11.
- Wikipedia. 2018a. "Standard library." Wikipedia, October 29. Accessed 2018-12-11.
- Wikipedia. 2018b. "C standard library." Wikipedia, October 10. Accessed 2018-12-11.
- Wikipedia. 2018c. "C++ Standard Library." Wikipedia, March 22. Accessed 2018-12-11.
- Wikipedia. 2018d. "Java Class Library." Wikipedia, December 03. Accessed 2018-12-11.
- Winters, Titus. 2018. "What Should Go Into the C++ Standard Library." Blog, Abseil, February 27. Accessed 2018-12-11.
Further Reading
- Blekhman, Alex. 2008. "What Every Computer Programmer Should Know About Windows API, CRT, and the Standard C++ Library." CodeProject, August 22. Accessed 2018-12-11.
- Winters, Titus. 2018. "What Should Go Into the C++ Standard Library." Blog, Abseil, February 27. Accessed 2018-12-11.
- Dawes, B., H. Hinnant, B. Stroustrup, D. Vandevoorde, and M. Wong. 2018. "Direction for ISO C++." Doc no. P0939r0, February 10. Accessed 2018-12-11.
Article Stats
Cite As
See Also
- C Standard Library
- C++ Standard Library
- Boost C++ Libraries
- Apache Commons
- International Organization for Standardization
- Internet Engineering Task Force