编程与软件工程drdobbs.com编辑精选
想写一门自己的编程语言?
So you want to write your own language?
2014 — 2017,它一次次回到首页
黑点是上首页(≥ 50 分)的那次投稿,空心点是没冲上去的投稿,点越大分数越高。
导读
这篇发表在 Dr. Dobb's 上的文章面向想自己动手设计编程语言的开发者,讨论了从解析器实现(作者建议手写递归下降而非依赖编译器编译工具)到语言设计原则(如不要盲目追求少敲键盘、要重视熟悉度和友好的错误信息)的诸多实践建议,并指出推广一门新语言同样是不小的工程。
为什么经久不衰:它把造语言从浪漫冲动落到工程现实:设计取舍、工具链和推广都绕不开,多年后仍是入门造语言者的务实指南。
HN 评论精选
赞同文章观点:手写解析器比用编译器生成工具体验更好,但要警惕过度引入上下文敏感性。
我很喜欢这篇文章反对使用编译器编译工具的建议。我用这类工具的体验总是更糟。不用它们时最大的风险(尤其是手写递归下降时)是忍不住把语法做得比必要的更上下文敏感。
stormbrew查看英文原文
I really like that this article suggests against using compiler compilers. My experiences have always been much worse when using them. I think the biggest risk when not using them (especially if you're writing a recursive descent by hand) is avoiding the temptation to make things more context sensitive (not necessarily in the rigorous language theory sense) than absolutely necessary.
建议用 s-表达式简化解析工作,并鼓励站在前人基础上享受造语言的乐趣。
我不请自来但有偏见的建议:用 s-表达式。别为了对积 types 和整数做计算就触发解析。如果你能想出比 s-表达式更好的方案,就用那个。另外,站在巨人的肩膀上继续伸手摘星,语言设计非常有趣。
agentultra查看英文原文
My unsolicited, biased advice: use s-expressions. Don't trigger a parse simply to compute with the sums of products and integers [0]. If you can think of something better than s-expressions use that. Also, read http://this-plt-life.tumblr.com/ and don't take yourself too seriously. Stand on the shoulders of giants and continue reaching for the sky. Languages are super fun. [0] http://www.infoq.com/interviews/mccarthy-elephant-2000
真实案例:为拯救遗留代码库而自建语言/编译器是可行且值得的,但维护成本和招人难度很高。
自己造语言的另一个理由:我有一个用 80/90 年代封闭 4GL 写的庞大代码库。选择是 a) 继续凑合用,b) 抛弃重写但丢失多年积累的业务规则和逻辑,c) 开发一个编译器/运行时并从那里演进。我选了 c),事后看极其雄心勃勃但很庆幸这么做了。代价之一是很难招到愿意维护这个'科学怪人'的程序员。
geekpowa查看英文原文
Another reason for writing your own: I have a sprawling codebase written in a 80s/90s era closed 4gl. Crossroads. a) keep kicking this can down the road using what I have inspite of its obvious and increasingly imposing limitations, b) discard it and rewrite or code in something else inspite of loss of hard won business rules, logic, behaviours and feel of the code over the years or c) develop a compiler/runtime and evolve it from there. Went with c). In hindsight was incredibly ambitious but glad I did it. Been evolving compiler and runtime steadily. Now at point where I am starting to think about how to bend the language to discourage certain anti-patterns the language by design encourages and move the code base away from these anti-patterns (excessive use of global variables for one). Alot of consequences I have to accept with this approach though, one obvious one is it is hard to find and hire programmers who want to work on the frankenstein's monster I've created here. Programming seems easy when it's all new and shiny and you are minting things for the first time. Old code is challenging, there are no obvious solutions forward, none I've found at least.
认同文章核心观点:语言设计不应以减少按键为目标,可读性和错误信息更重要。
非常同意'少敲键盘是伪神'那段:没人需要又一个 Perl 或 bash。语言应该尽可能简洁,但不能更简洁。关于熟悉度和友好错误信息的观点也很好。
jakub_g查看英文原文
> These are false gods: > Minimizing keystrokes. Maybe this mattered when programmers used paper tape, and it matters for small languages like bash or awk. For larger applications, much more programming time is spent reading than writing, so reducing keystrokes shouldn't be a goal in itself. Of course, I'm not suggesting that large amounts of boilerplate is a good idea. Couldn't agree more! No one needs another perl or bash. Languages should be as concise as possible, but not more. Also good points about familiarity and helpful error messages.
历次讨论
同类还值得读
开源应用架构
The Architecture of Open Source Applications
《开源软件架构》(AOSA)是一本在线免费书,邀请知名开源项目的作者亲自剖析其内部设计,涵盖 SQLAlchemy、LLVM、Audacity、Apache、Bash 等系统。
编程与软件工程上首页 9 次 · 2011–2024aosabook.org编辑精选编程语言简史:简短、不完整且多半错误
A Brief, Incomplete, and Mostly Wrong History of Programming Languages
一篇以戏谑、故意不准确的方式回顾编程语言史的博客文章,用夸张轶事和讽刺定义串起 Lisp、C、C++、Java、JavaScript、PHP 等语言。
编程与软件工程上首页 8 次 · 2009–2021james-iry.blogspot.comSQLite 是如何测试的
How SQLite is tested
SQLite 官方文档页,系统介绍 SQLite 的测试体系:多种测试方法(TCL 测试、模糊测试、回归测试、静态分析等)和海量测试用例,展示了这个小型开源项目如何靠极致测试获得…
编程与软件工程上首页 8 次 · 2009–2025sqlite.org编辑精选高级编程语言(2009)
Advanced programming languages (2009)
Matt Might 的经典文章,按用途推荐“高级编程语言”:如果追求就业就选主流语言,如果追求表达力、学术研究或创业,则推荐 Haskell、OCaml、Scala 等函数式语…
编程与软件工程上首页 8 次 · 2009–2022matt.might.net我的 Forth 与栈机器经历
Yosefk - My history with Forth & stack machines
作者以亲身经历回顾了使用 Forth 语言和栈式机器的历程:既赞叹其简洁优雅、代码量小、可自举的优点,也坦率指出栈操作在实际编程中的痛苦,以及 Forth 社区文化中的问题。
编程与软件工程上首页 8 次 · 2010–2024yosefk.com编辑精选