编程语言与软件工程2012cloud.github.com
一种实用的 Clojure 可选类型系统
A Practical Optional Type System for Clojure
进阶 · 约 60 分钟读完前置知识:Clojure 基础、类型系统基础、函数式编程
导读
这篇论文(Clojure 社区知名的 Typed Clojure 项目的基础)研究如何为动态语言 Clojure 设计并实现一个实用的可选静态类型系统。作者 Ambrose Bonnaire-Sergeant 验证了该系统能对实际代码(如 algo.monads 库)进行几乎完整的类型检查,证明可选静态类型对 Clojure 既可行又有用。
HN 关注点:动态语言能否引入静态类型这一经典话题,讨论焦点集中在可选类型的实用性、multimethods/protocols 等语言特性如何与类型系统交互,以及动态与静态类型之争。
HN 评论精选
这几条评论里:支持 1 质疑 1 补充 1 亲历 1
支持作者/支持者视角:肯定该系统的实用价值,同时担忧无类型库对类型化代码的使用障碍
总体而言,这项工作得出的结论是:为 Clojure 设计并实现可选静态类型系统既实用又有价值。我是类型安全的坚定拥护者,这太令人兴奋了,我一定会试试 Ambrose 的工作。快速浏览后发现 algo.monads 几乎完全可以通过这个系统做类型检查,非常激动。我有几个问题:multimethods 是无类型的,有人能说说惯用 Clojure 代码中 multimethods 的使用频率吗?另外,这项工作最终能否让 protocols 变成完整的 type-class(允许基于 protocol 方法的返回类型进行分发)?期待 Typed Clojure 在 Clojure Conj 2012 的演讲视频。我唯一的担心是:可选类型可能不如『可选去类型』有用——当库没有类型时,在类型化语言中使用它们很痛苦,反过来则不然。
pufuwozu查看英文原文
Overall, the work described in this dissertation leads to the conclusion that it appears to be both practical and useful to design and implement an optional static type system for the Clojure programming language. I'm a huge type safety fan (see http://roy.brianmckenna.org/) so this is pretty amazing. I'm definitely going to play around with Ambrose's work. Had a quick look, it's really exciting that the algo.monads was almost completely type-checkable with this system. Leaves me with a couple of questions: Multimethods are untyped. Anyone able to comment on how often multimethods are used in idiomatic Clojure code? Anyone know if this work could eventually allow protocols to become full type-classes (allowing dispatch based on return type of protocol methods)? Am I misunderstanding how protocols are compiled? Hopefully the videos for Typed Clojure at Clojure Conj 2012 will be posted soon after the talk is given :) My only fear is that optional typing would be less useful than optional untyping. When you have libraries that are untyped, they're a pain to use from a typed language. The other way around is not true.
亲历论文作者本人现身,欢迎读者反馈指正
说明一下,任何指正都非常欢迎,这是我的第一篇论文,还有很多要学!请把意见发到 abonnairesergeant at gmail dot com。
ambrosebs查看英文原文
I'll just note that any corrections are more than welcome, this is my first paper and I've got a lot to learn! Please send them to abonnairesergeant at gmail dot com.
质疑质疑立场:认为 Clojure 背离了经典 Lisp 传统,对其引入静态类型持批评态度
经典 Lisp 的一个显著特征是:类型标签属于值而非变量,类型安全检查在运行时进行。一切都是引用(指针),一切都是一等对象,一切都是表达式(统一语法)。讽刺的是,Clojure 是 Lisp 国度里的 Java——他们破坏了抽象层,把逻辑和实现搅在一起,引入了不同风格的括号以及冗余无关的数据结构,毁掉了『一切皆列表』的魔力。看看经典的 3 行 keep 函数变成了什么样。
dschiptsov查看英文原文
One of the distinguishing features of a classic Lisp is that values, not variables have a type-tag and the type-safety checking is performed at runtime. Everything is a reference (a pointer), everything is a first-class object (could be passed anywhere), everything is an expression (uniform syntax). Ironically, Clojure is, a Java in the land of Lisp. They broke the abstraction layers, mess up logic with implementation, introduce not just different kind of parenthesis, but redundant and irrelevant data-structures and ruined the magic of "everything is a list". Look what a classic 3-lines 'keep function became.)
补充温和中间派:认可论文质量,但认为强类型并非必需,动态类型在休闲项目中更轻松
这真的很棒,完成得非常精致。不过最近我遇到一些认为编程必须用强类型的人,这让我觉得挺奇怪。我认为类型系统确实有其价值,是保证正确性的好方法,但在业余项目里不用折腾类型也很舒服。总之,好论文。
th0ma5查看英文原文
This is really great, and immaculately put together. Recently though I've come across people who think that you need strong types when programming, and this is really weird to me. I think it has its place for sure, and is a great way to ensure you're being correct, but I also really like not having to mess with types on hobby projects and such for sure :D Anyway, great paper.
相关资源
从这篇论文所有 HN 讨论帖的全部评论里整理出来的链接。
历次讨论
- 2012Hacker News 讨论帖164 分 · 51 评
同领域还值得读
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 分钟编辑精选