编程与软件工程ybrikman.com
深奥的编程范式
Esoteric programming paradigms
2017 — 2019,它一次次回到首页
黑点是上首页(≥ 50 分)的那次投稿,空心点是没冲上去的投稿,点越大分数越高。
导读
这篇文章介绍了六种非传统的编程范式(如逻辑编程、并发编程、依赖类型等),通过代码示例展示它们如何改变程序员思考问题的方式。它并非浅尝辄止,而是深入探讨每种范式的核心思想。
为什么经久不衰:它之所以经久不衰,是因为这些范式持续挑战主流编程思维,而评论区的专业讨论不断纠正细节、补充新进展,使其成为值得反复阅读的起点。
HN 评论精选
文章误称Prolog数独是暴力搜索,实际用了约束逻辑编程剪枝;Prolog也能轻松实现高效算法。
关于Prolog代码我有两点评论:首先,文章声称“上面的数独求解器进行暴力搜索”,但事实并非如此。相反,文章展示的Prolog数独公式使用了有限域约束逻辑编程(CLP(FD))这一强大技术,它在搜索解之前和搜索过程中自动进行剪枝。这在实际中有效消除了大部分搜索空间,只有在几乎无法从初始约束推导出任何信息时才会退化为暴力搜索。对于数独,剪枝尤其有效,许多情况下可以完全消除搜索,因为初始约束(提示)基本决定了整个解。其次,是的,在Prolog中很容易写出O(n!)搜索算法。然而,在Prolog中实现更高效的搜索算法也同样容易。例如,下面是Prolog中的快速排序:…… 注意“先较小元素,再枢轴元素,再较大元素”的声明式描述在Prolog中多么自然。这只需要一个合适的partition/4实现,最多7行Prolog代码即可完成。
zmonx查看英文原文
I have two comments about the Prolog code: First, the article claims: "the sudoku solver above does a brute force search", but that is specifically not the case. In fact, quite the opposite holds: The Prolog Sudoku formulation shown in the article uses a powerful technique known as Constraint Logic Programming over Finite Domains, which automatically performs pruning before and also during the search for solutions. This effectively eliminates large portions of the search space in practice, and degenerates to brute force only in those cases where almost nothing can be deduced from initial constraints. In the particular case of Sudoku, the pruning is especially effective and can in many cases eliminate the search entirely, since the initial constraints (hints) basically determine the whole solution. Second, yes, it is easy to write an O(n!) search algorithm in Prolog. However, it is almost as easy to implement much more efficient search algorithms in Prolog. For example, here is Quicksort in Prolog: quicksort([]) --> []. quicksort([L|Ls]) --> { partition(Ls, L, Smalls, Bigs) }, quicksort(Smalls), [L], quicksort(Bigs). Note how natural the declarative description of "first the smaller elements, then the pivot element, then the bigger elements" is in Prolog. This only requires a suitable implementation of partition/4, which is very easy to implement in at most 7 lines of Prolog code.
Prolog是ISO标准语言,语法极简且影响数据库查询语言,不应被视为晦涩。
我不知道Prolog是否该被称为“深奥”。毕竟Prolog是ISO标准化语言,其语法在我读过的关于概念数据库系统和查询语言设计的大多数论文中已经使用了四十多年。这并不奇怪,因为Prolog语法基于运算符优先级文法概念,可以说是极简的。最近人们对Datalog也很有兴趣,不仅将其视为可判定的逻辑片段(这也已经使用了几十年),还将其视为实用的非SQL数据库查询语言和Prolog语法的适当子集。
tannhaeuser查看英文原文
I don't know if Prolog should be called esoteric. Prolog is an ISO-standardized language after all, and its syntax has been used for 4+ decades now in most papers on conceptual database system and query language design I've read. Which isn't surprising since Prolog syntax, being based on operator-precedence grammar concepts, is arguably as minimalistic as it gets. There's definitely also a lot of interest lately in Datalog, not just as a decidable logic fragment (which has been used for decades as well), but also as a practical non-SQL database query language and proper Prolog syntax subset.
同步编程适合交互/并发程序和形式推理,正从安全关键领域走向主流。
我想补充同步编程[1],它特别适合交互式或并发程序以及形式推理,并已在安全关键实时系统的工业应用中取得成功。例子包括Esterel[2]和SCADE,在实时领域之外还有Céu[3]和Eve[4](后者基于Dedalus[5],结合了同步编程与逻辑编程)。作为一个热爱形式化方法并认为当今大多数主流软件系统主要是交互式和/或同步的人,我认为这种范式有很大未开发潜力,我很高兴看到它通过Eve等语言慢慢从安全关键系统走向主流。
pron查看英文原文
To this I would add synchronous programming[1], which is particularly suited for interactive or concurrent programs and formal reasoning, and has had success in industry in safety-critical realtime systems. Examples include Esterel[2] and SCADE, and outside realtime, Céu[3] and Eve[4] (the latter is based on Dedalus[5], which combines SP with logic programming). As someone who loves formal methods and believes most mainstream software systems today are mostly interactive and/or synchronous, I think this paradigm has a lot of untapped potential, and I'm glad to see it slowly move out of safety-critical systems into the mainstream, in languages like Eve. [1]: https://en.wikipedia.org/wiki/Synchronous_programming_language [2]: https://en.wikipedia.org/wiki/Esterel [3]: http://www.ceu-lang.org/ [4]: http://witheve.com/ [5]: https://www2.eecs.berkeley.edu/Pubs/TechRpts/2009/EECS-2009-173.pdf
依赖类型讨论中Coq已在2019年成为形式验证的主流,并重新定位为形式证明管理系统。
原Hacker News讨论(文章顶部也有链接):https://news.ycombinator.com/item?id=7565153。我觉得有趣的是,关于依赖类型的讨论列出了Idris和Coq作为语言并讨论了形式验证,但主要关注Idris和Scala的Shapeless……但据我所知,Coq在2019年实际上在这个领域胜出了,Coq甚至专门为此重新品牌化[0]。[0] Coq是一个形式证明管理系统。
merlincorey查看英文原文
Original HN discussion (linked at top of article as well): https://news.ycombinator.com/item?id=7565153 I find it interesting that the discussion on Dependent Types lists Idris and Coq as languages and discusses Formal Verification but mostly focuses on Idris and Scala with Shapeless... but to my knowledge, Coq has actually won out in 2019 for this, and Coq has even branded itself for this specifically[0]. [0] https://coq.inria.fr/ - Coq is a formal proof management system.
历次讨论
同类还值得读
开源应用架构
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编辑精选