小型程序和语言
Small Programs and Languages

原始链接: https://ratfactor.com/cards/pl-small

作者探讨了小型编程语言的吸引力,将其与更大、更具表达能力的语言进行了对比。汇编语言虽然概念简单,但由于CPU架构的复杂性而极具挑战性;而Forth、Lisp和Tcl等语言则以最少的语法提供了强大的功能和灵活性,需要改变思维方式。Lua和JavaScript在大小和表达能力之间取得了平衡。 David Ungar的理念强调简洁胜于表达能力,认为清晰度至关重要,即使这意味着要编写更多代码。精心设计的小型语言可以实现令人惊讶的表达能力,Forth、Lisp和Tcl就是很好的例子。像JavaScript的Ramda这样的库,也体现了大小和功能之间的权衡,甚至可能感觉像学习一门全新的语言。最终,小型工具的简洁性往往带来独特的快乐和效率感。

This Hacker News thread discusses small programs and languages, sparked by an article highlighting their importance, especially in relation to Kolmogorov complexity. User "tromp" shares their work on creating a minimal language for minimal-size programs, leading to a discussion about universal combinators and encoding efficiency. Implementations of Binary Lambda Calculus (BLC) in various languages are shared. The thread also explores the practical applications and learning experiences associated with small languages, with some users lamenting that Lisp dialects created on a project basis aren't easily applicable elsewhere, unlike opinionated languages. Several users mention specific small languages like Cwerg, Meta II, Oberon, and others, along with links to implementations and resources. The inherent context required for interpreting code related to Kolmogorov Complexity is also briefly discussed.
相关文章
  • (评论) 2024-01-17
  • 实现Forth语言 2025-06-03
  • (评论) 2024-05-23
  • (评论) 2024-04-10
  • 我为什么用 Lisp 编程 2025-04-11

  • 原文

    Small programs are interesting. But I’m also interested in small programming languages.

    Generally speaking, the smaller the language, the less expressive it is.

    One of the most well-known, least expressive languages is assembly.

    Assembly languages are very syntactically and conceptually simple. There’s not much language at all: it’s mostly a rigid sequence of opcode mnemonics. Even with macros, writing in assembly is mostly about understanding the puzzle of a particular CPU’s instruction set architecture, or ISA. (You can prove this by comparing the syntax of assembly for CISC and RISC processors. The puzzle is totally different, while the language remains practically unchanged.)

    An honorable mention must be made here for SNOBOL, which is kind of like assembly language both for the rigid syntactic reasons listed above and also because it presents a similar control flow challenge. Like a CPU, it only understands jumps and call/return. (In every other way, SNOBOL is wildly different, being a string matching and replacing language. It’s weird and fun and highly effective.)

    Moving on to syntactically tiny "high-level" languages, these three are brilliant:

    • Forths win just about any "smallness" contest. The only syntactical construct is the space character. Forths are mind-bendingly flexible and powerful in a way that is downright disturbing.

    • Lisps, (especially Scheme?), have small core languages with very simple syntax and enormous expressive power and flexibility.

    • Tcl deserves to be mentioned with Forth and Lisp. Tcl is wild because everything is a string in a way that is hard to appreciate at first. You can construct your own language in Tcl just as you can with Forth or Lisp.

    Forth, Lisp, and Tcl only require you to understand a few core ideas and give you limitless power in return. You could fit the syntactic core of these languages on an index card or less.

    And yet, to wield these tools effectively requires a massive shift in thinking if you’re used to "normal" Algol-like procedural languages.

    So how about something that is both small and simple and doesn’t require a blood sacrifice?

    I think the Lua programming language fits the bill. Check out how small the core language is:

    I’ve got the printed book version of this document and it’s a thin book! The Lua language is covered in the beginning and it is just 27 pages. 27 pages! I have game manuals longer than that.

    The C language is pretty small. I don’t think it’s super easy to program effectively and safely with C, but there’s no denying it’s compact and pretty expressive for its size.

    Newcomer Zig is C-like. But I think it’s actually quite large and you need to know a lot of it to use it effectively. (I’m also a fan of Zig and think it’s totally worth it. The size is there for a reason.)

    JavaScript has a core language that is quite small. Probably on par with Lua, actually. Functions, arrays, and objects (used as dictionaries) are pretty much all the JS I use and I like it that way!

    As with the natural human languages, the trade-off with a bigger programming language is, hopefully, greater expressivity.

    Small or expressive. Which way should you lean?

    In a wonderful talk by David Ungar (wikipedia.org) titled Self and Self: Whys and Wherefores, he laments the mistake of Self’s multiple inheritance:

    "It’s far better to make a system a little too simple so a person has to write extra stuff, even write it twice with a comment that says, 'Look over here,' than to have a system that acts in strange ways and nobody can understand why. So, simplicity trumps expressiveness."

    Got that? Here’s the bullet from the slide to help you remember:

    I think small languages can also be fairly expressive, but only with very, very careful design. Recall Forth, Lisp, and Tcl.

    Microworlds: The idea of small, self-contained, learnable programming environments also has a David Ungar connection I discovered while watching his talk. See "ARK" on my Microworlds card. (Smith and Ungar co-created the Self language (selflanguage.org), which is a notable milestone in programming and still under active development to this day.)

    Libraries: Another easily overlooked aspect of a programming language’s apparent size is its "standard library" of functions, data structures, and methods.

    I think function libraries are subject to the exact same size versus expressiveness challenge.

    For example, learning the Ramda (ramdajs.com) functional programming library for JavaScript was very much like learning a new programming language and I never managed to learn all of it. The composability of Ramda and the consistency of its curried functions was extremely eye-opening to me. A little bit of Ramda goes a long way!

    The feels: Concision in our tools has a certain quality that goes beyond utility. Little things just spark joy, you know?

    Why are small things so delightful?

    联系我们 contact @ memedata.com