编程语言与软件工程2009janestreetcapital.com
Caml Trading:华尔街的函数式编程实践
Caml Trading: Experiences in Functional Programming on Wall Street
进阶 · 约 35 分钟读完前置知识:函数式编程基础、OCaml 语法、垃圾回收与运行时基础
导读
这是 Jane Street 团队(Yaron Minsky 等)关于在华尔街金融交易系统中使用 OCaml 的经验报告,讲述了他们为何选择函数式语言、哪些语言特性在实际工程中带来优势、哪些带来麻烦,并给出相当坦率的评估。文中也讨论了 OCaml 的对象系统、垃圾回收器等具体取舍,例如缺少并发 GC 在单芯片多核趋势下逐渐成为限制。
HN 关注点:函数式语言在工业界的真实落地经验,尤其是“带缺陷的实战复盘”而非宣传软文,以及金融行业从 Java/C# 转向 Erlang/OCaml/Ada 的趋势。
后来怎么样
这篇报告让 Jane Street 的 OCaml 工业实践广为人知,成为函数式语言在金融交易系统中落地的经典案例,也长期影响关于 OCaml 运行时与并发 GC 的讨论。
HN 评论精选
这几条评论里:支持 2 质疑 1 补充 1
补充资深 OCaml 用户:赞赏类型推导与编译器简洁高效,但指出缺少并发 GC 是硬伤,并反驳 Jane Street 对 OO 的贬低。
看到 FP 被用在“真实世界”而不只是学术界,这很吸引人。我非常喜欢 OCaml,一直用它写大型项目,尤其钟爱 ML 系语言的类型推导和严格的静态类型;我希望更多人拥抱静态类型语言,这对代码正确性很有价值,而且编译器通常能生成性能更好的代码。我注意到 Jane Street 的人总是批评 OCaml 的面向对象部分;我发现类/对象在编写可扩展的软件框架时确实有用,虽然我也同意通常可以不用。不过 OCaml 处理对象的方式值得一看,和典型的 C++/Java/C# 很不一样。缺少并发垃圾回收器,在单芯片核数越来越多的趋势下确实越来越成为限制。但因为 GC 和编译器都很简单,OCaml 是那种你可以看目标代码并理解编译器在做什么的语言;更有趣的是,即使编译器很简单,它的优化也做得非常好。语言作者 Xavier Leroy 常被引用的一句话是“最差也有 C 代码 50% 的性能”。另外,对没试过函数式语言的人,我认为 OCaml 是最好的入门选择。
mas644查看英文原文
It's fascinating to see FP being used in the "real world" rather than academia! I absolutely love OCaml and use it all the time to write major projects. I've always loved the type inferencing and super strict static typing of the ML family of languages. I wish people would embrace statically typed languages more...there's a lot to be said for code correctness and OCaml does it in a very natural way. That and the compiler can usually generate significantly better performing code. I always notice those at Jane Street rip on the OO aspects of OCaml. The place I found classes/objects to come in handy are when you write extensible software frameworks...though I agree, usually you can do without. However, it is worth taking a look at how OCaml approaches objects...quite different from what you would find in your typical C++/Java/C# style language. The lack of concurrent garbage collector is really becoming a limitation with the trend towards higher number of cores on a single die. However, because the GC and compiler are so simple, OCaml is one of those languages where you can look at object code and understand what the compiler is doing. What's even more interesting is that even though the compiler is really simple, it does a fantastic job at optimization. The creator of the language, Xavier Leroy, is often quoted as saying that "worst case 50% performance of C code". Oh one other thing...for those that have not tried a functional language, I think OCaml gives the best introduction. You can code imperatively with it if you want, but you'll ween yourself off of it in time in exchange for more declarative, functional techniques. Oh and you won't look back! ;)
支持赞赏论文坦率披露缺陷,并观察到金融业从 Java/C# 转向 Erlang/OCaml/Ada。
这是一篇很有意思的读物。你经常看到各种吹捧文章告诉你该用某种语言,但这里是一个清醒而有经验的作者,说明 OCaml 在他们那里到底效果如何,而且把缺陷(warts)也讲了出来——缺陷才是最值得了解的部分。金融行业现在的变化也很有意思:Java/C# 越来越少,Erlang、OCaml 和 Ada 越来越多。计算机极客赢了。
spitfire查看英文原文
This was an interesting read. You see lots of puff pieces telling you why you should use a language, but here's a sober experienced voice explaining how ocaml worked out for them. Warts and all. The warts are the most important part to know about. It's sort of interesting what's happening in the finance industry today. You see less and less java/c# and more erlang, ocaml and ADA. The CS geeks won out.
质疑质疑:若 OCaml 需靠 MLton 式全程序优化弥补性能,为何不直接用 SML/MLton?
文中写道:“简而言之,程序员有时会回避那些让 OCaml 用起来如此愉快的特性。可以通过更激进的优化技术来解决这个问题(例如 MLton 标准 ML 编译器所用的全程序优化)。可惜这种优化短期内不太可能出现在 OCaml 上。”那么,为什么用 OCaml 而不是用 MLton 实现的 Standard ML?
bravura查看英文原文
"In short, programmers may sometimes avoid the same features that make OCaml such a pleasant language to program with. It is possible to address this problem by using more aggressive optimization techniques (e.g., whole-program optimization as is used in the MLton Standard ML compiler (MLton, 2007)). Unfortunately, it does not seem likely that such optimization will be available any time soon for OCaml." Then why OCaml over Standard ML using the MLton implementation?
支持论文的价值在于语言特性的得失分析可迁移到其他语言。
绝对值得一读。他们讨论了哪些语言特性带来了优势和劣势,因此这些经验对使用其他语言的程序员也同样有借鉴意义。
cema查看英文原文
Definitely worth a read. They discuss which language features gave them advantage and disadvantage and so the lessons can be used by programmers in many other languages as well.
历次讨论
- 2009Hacker News 讨论帖60 分 · 10 评
- 2011Hacker News 讨论帖85 分 · 24 评
同领域还值得读
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 分钟编辑精选