提问 HN:标准库应该包含什么?
1 分•作者: vodou•9 个月前
我知道,我知道……这个问题里有无数个“具体情况具体分析”。但我们还是试着讨论一下吧。
在Hacker News上阅读多年后,我见识了无数关于各种编程语言标准库的观点,例如,它们应该如何设计,应该(和不应该)包含什么等等。
C标准库非常精简,主要侧重于底层功能。每个人都期望自己实现动态数组,或者从无数个可用库中选择一个实现。而且,显然,以空字符结尾的字符串是魔鬼的杰作。C++拥有一个更广泛的标准库,围绕泛型编程技术构建,使用容器、迭代器和以可组合的方式应用的算法。它相当优雅和强大,但对初学者来说不太直观。与更现代的语言相比,它也有一些明显的遗漏。Python自带“电池”,以非常丰富的标准库的形式呈现。然而,Python软件基金会(PSF)倾向于时不时地“破坏用户空间”,通过弃用旧模块,例如像CGI这样的“无聊”技术,或者存在已知安全问题的模块。(我对JS、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.)