TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

What makes a good standard library?

4 点作者 zaksingh超过 2 年前
I&#x27;ve been working on a new programming language and I&#x27;ve started to think that the design of a language&#x27;s standard library (in terms of error handling, consistent naming, consistent argument ordering, types, etc) has a greater impact on the learning curve and ergonomics of a language than the more commonly discussed syntax differences and unique features.<p>For example, I can _never_ remember if a function in JS or Python mutates a list&#x2F;object or returns a new copy. Without editor hints this was an annoyance, as I&#x27;d have to try it out, check the source, or search the docs. Such issues never happen with a functional standard library (as in Clojure) where you can always assume immutability.<p>Meanwhile in Clojure, if I&#x27;ve been gone from the language for a while I forget which list functions return a lazy sequence, a seq, or a vector, and I find myself making frustrating errors as a result. Or how some functions (like map and filter) take the collection as the last argument, and a few others take it as the first.<p>It seems like a poor standard library design requires acquiring much more &#x27;trivia&#x27; about the language to be successful, to write performant code, and (sadly) to pass many technical interviews.<p>What do you think makes a good standard library? A bad one? Do you have any favorite features you&#x27;d like to see more of?

3 条评论

lgreiv超过 2 年前
It should be consistent in its use of idioms in order to reduce the number of lookups required. Still, it should be documented extraordinarily well, because it then can serve as an on-ramp to best practices for novices. Further, it should be tailored to the intended use case of the language to stay lean but usable to carry an application as far as possible without needing a heap of dependencies.<p>I appreciate these qualities in the standard library of Crystal [1], to name an example.<p>[1] <a href="https:&#x2F;&#x2F;crystal-lang.org&#x2F;api&#x2F;1.7.0&#x2F;" rel="nofollow">https:&#x2F;&#x2F;crystal-lang.org&#x2F;api&#x2F;1.7.0&#x2F;</a>
butternoodle超过 2 年前
* Predictability and convention are more important than totally clean design. Over the course of a language lifetime, code style best practice is going to change so you almost certainly won&#x27;t have uniform interfaces. Your Clojure example of functions passing the input as first vs last is actually an example of this -- functions that work on sequences expect the last arg, and functions that work on datastructures expect the first arg. It&#x27;s an official convention, check out different uses of the -&gt; and -&gt;&gt; macros and you&#x27;ll always see it.<p>* Some form of discoverability. Ideally there&#x27;d be good docs available explaining the behaviour of the library in human friendly language, with multiple code examples. Bonus points for making the library open source and linking directly to the implementation from documentation.<p>* No breaking changes. It&#x27;s better to create a new library than try and shoehorn a significantly different release into semantic versioning for the sake of it.<p>* &quot;Escape hatches&quot; for effectful functions to override default behaviour. For example, a HTTP client library isn&#x27;t going to be very useful if you can&#x27;t override pretty much any configuration property.<p>* Being explicit about any side effects resulting from the code, either in naming or by documentation.
tmtvl超过 2 年前
Something I really like about Scheme is how mutators are generally suffixed with an exclamation point and predicates with a question mark. For example:<p><pre><code> (null? spotted-ufos) (vector-set! drakes 0 maui-mallard) </code></pre> Having a simple and clear convention like that is something I consider good design.