编程语言与软件工程2018staff.um.edu.mt
小语言(1986)
Little Languages (1986)
入门 · 约 30 分钟读完前置知识:编程经验、Unix 命令行工具
导读
这篇 1986 年的文章围绕“小语言”(little languages)展开,讨论为狭窄问题域设计专用小型语言的思路与价值,并说明这类语言如何简化特定编程任务。它关注的是专用语言与通用语言在表达能力和适用范围上的差异。
HN 关注点:是因为它触及 DSL/专用语言与通用语言之间的经典取舍:小语言在窄任务上高效,但任务变复杂后是否应换成通用语言。
后来怎么样
推广了“为狭窄领域设计小语言”的思路,成为 Unix 工具传统和后续领域特定语言(DSL)讨论中的经典参考。
HN 评论精选
这几条评论里:质疑 2
质疑认为独立小语言缺陷多,应把领域子语言嵌入 Scheme 这类通用语言。
反方观点:摘要指出,“小语言”式系统编程方法有缺陷:低效、脆弱、易错、表达力不足且难以组合。更好的做法是把任务专用子语言嵌入像 Scheme 这样强大且语法可扩展的通用语言中。作者展示了在 scsh(面向 Unix 系统编程的 Scheme 环境)中实现的两个嵌入语言:第一个是高层进程控制记法,第二个提供类似 Awk 的处理。这种嵌入方式很有力:例如嵌入的 Awk 系统只用了标准 C 版 Awk 所需代码的 7%,却明显更具表达力。
waterhouse查看英文原文
Counterpoint: "A Universal Scripting Framework, or: Lambda: the ultimate “little language”" "Abstract. The “little languages” approach to systems programming is flawed: inefficient, fragile, error-prone, inexpressive, and difficult to compose. A better solution is to embed task-specific sublanguages within a powerful, syntactically extensible, universal language, such as Scheme. I demonstrate two such embeddings that have been implemented in scsh, a Scheme programming environment for Unix systems programming. The first embedded language is a high-level process-control notation; the second provides for Awk-like processing. Embedding systems in this way is a powerful technique: for example, although the embedded Awk system was implemented with 7% of the code required for the standard C-based Awk, it is significantly more expressive than its C counterpart." http://www.ccs.neu.edu/home/shivers/papers/ll.ps
质疑小语言只适合小任务,复杂后应改用 Perl/Python 等通用语言。
小语言适合小项目。程序长大后,小语言会拖后腿,需要一门“成人语言”。事实上所有小语言都相当原始,这是设计使然:它们只针对特定狭窄用途;超出这个范围就表达力差、笨重且低效。现实任务常需要多种小语言:先用 Awk 做简单文本抽取,再用 Sed 做文本转换,最后用 Bash 粘合。但很快这组脚本会变得难维护和扩展,不如用一个 Perl 或 Python 程序替代,后者能完成上述所有事情甚至更多。所以底线是:任务合适就用小语言,但要清楚其局限。
alexeiz查看英文原文
Little languages are good for little programs. Once your program grows up, a little language starts holding it back. Your program needs a language for grown-ups. The truth is all little languages are quite primitive, and this is by design. Little languages are designed for a specific narrow purpose. Beyond that narrow purpose they are much less expressive, clunky and inefficient. Real life tasks often require more than one little language. You can start with a simple text extraction using Awk, then use Sed for text conversion, and glue it all together with Bash. But very soon it becomes hard to maintain and extend this collection of scripts and easier to replace them with one Perl or Python program, which can do all of the above and more. So the bottom line is, use little languages then they suit your task, but know their limitations.
相关资源
从这篇论文所有 HN 讨论帖的全部评论里整理出来的链接。
历次讨论
- 2018Hacker News 讨论帖78 分 · 17 评
- 2024Hacker News 讨论帖175 分 · 29 评
同领域还值得读
Google 的软件工程(2017)
Software Engineering at Google (2017)
介绍了 Google 的软件工程实践,包括其单一代码库(monorepo)、几乎全部开发在主干进行而非分支、代码审查、构建系统 Blaze、协议缓冲区等工具与流程,并讨论了频繁重…
编程语言与软件工程2017 · 1,127 分 · 465 评 · 引用 15入门 · 约 45 分钟编辑精选Peter Naur:编程作为理论构建 (1985)
Peter Naur – Programming as Theory Building (1985)
Peter Naur 1985 年的经典论文《Programming as Theory Building》提出:编程的本质不是写代码或文档,而是在程序员头脑中构建对程序及其运行…
编程语言与软件工程2016 · 629 分 · 74 评入门 · 约 45 分钟编辑精选SciPy 1.0:Python 科学计算的基础算法
SciPy 1.0: fundamental algorithms for scientific computing in Python
这篇发表于 Nature Methods 的论文介绍了 SciPy 1.0——Python 科学计算生态的基石库,涵盖其核心算法模块(优化、积分、插值、线性代数等)、软件架构与社…
编程语言与软件工程2020 · 387 分 · 98 评入门 · 约 45 分钟编辑精选Lisp 的历史(1979)
History of Lisp (1979)
这是 Lisp 发明者 John McCarthy 于 1979 年为 HOPL(编程语言史)会议撰写的回顾文章,讲述 Lisp 的起源、设计动机与早期演进,文中也涉及 if 表…
编程语言与软件工程2018 · 352 分 · 44 评入门 · 约 45 分钟编辑精选使用 NumPy 进行数组编程
Array Programming with NumPy
这篇 Nature 文章介绍 NumPy 的数组编程模型及其在科学计算中的核心作用:以 ndarray 为中心,通过向量化操作让 Python 高效处理多维数组。
编程语言与软件工程2020 · 318 分 · 134 评入门 · 约 40 分钟编辑精选