问HN:标准库中应该包含哪些内容?
我知道,我知道……这个问题中包含了无数的“这要看情况而定”。但我们还是试试看吧。
在多年阅读 Hacker News 的过程中,我遇到了许多关于各种编程语言标准库的观点,例如,它们应该如何设计,应该包含什么(以及不应该包含什么)等。
C 标准库非常简约,主要集中在低级功能上。每个人都被期望实现自己的动态数组,或者从成千上万的可用库中选择一个实现。而且,显然,空字符终止的字符串是魔鬼的作品。C++ 拥有一个更为广泛的标准库,围绕使用容器、迭代器和算法的泛型编程技术构建。它相当优雅且强大,但对初学者来说并不太直观。与更现代的语言相比,它也有一些显著的缺失。Python 则提供了“开箱即用”的丰富标准库。然而,Python 软件基金会(PSF)时不时会通过弃用旧模块来“破坏用户空间”,例如像 CGI 这样的“无聊”技术或存在已知安全问题的模块。(我对 JavaScript、Go、Rust 等语言没有足够的把握来发表意见。)
那么,一个优秀的标准库应该是什么样的呢?什么会让你感到满意?在过去 50 多年的计算机发展中,我们学到了什么?你想要从链表到红黑树(甚至更远)的所有东西吗?图形和声音呢?(即使没有任何单一的 API 能让每个人满意。)XML?YAML?SIMD 抽象?在不引起愤怒的情况下,你该在哪里停止?又该从哪里开始?
(不,我并不是在创造一种新的编程语言。够了就是够了。)
查看原文
I know, I know... There are countless "it depends" baked into this question. But let’s try anyway.<p>After reading HN for years, I have encountered so many opinions regarding standard libraries in various programming languages, e.g., how they should be designed, what they should (and should not) include, etc.<p>The C standard library is very minimal, focusing mostly on low-level facilities. Everyone is expected to implement their own dynamic arrays or choose one implementation from a zillion available libraries. And, apparently, null-terminated strings are the work of the devil. C++ has a much more extensive standard library, built around generic programming techniques using containers, iterators, and algorithms applied in a composable way. It is rather elegant and powerful, but not very intuitive for beginners. It also has some notable omissions compared to more modern languages. Python comes with "batteries included" in the form of a very rich standard library. However, the PSF tends to "break user space" from time to time by deprecating older modules, such as “boring” technologies like CGI or modules with known security problems. (I am not comfortable enough to say anything about JS, Go, Rust, etc.)<p>So, what would a great standard library look like? What would make you happy? What have we learned about this after 50+ years of computing? Do you want everything from linked lists to red-black trees (and beyond)? Graphics and sound? (Even if no single API can please everyone.) XML? YAML? SIMD abstractions? Where do you even stop without causing anger? Where do you begin?<p>(No, I am not creating a new programming language. Enough is enough.)