编程语言与软件工程2018www2.dmst.aueb.gr
C 编程实践的演化:对 Unix 的研究
The Evolution of C Programming Practices: A Study of Unix (2016)
入门 · 约 45 分钟读完前置知识:C 语言基础、Unix 系统历史
导读
这篇 2016 年的 ICSE 论文通过分析 Unix 各版本(从早期版本到 FreeBSD 等)的源码演化,研究 C 语言编程实践随时间的变化,包括函数长度、缩进、goto 使用等编码风格指标的演变趋势。作者对 Unix 代码库进行了大规模的定量统计,以观察数十年来 C 编程习惯的变迁。
HN 关注点:是因为它用数据量化了 C 代码风格的演化,而 goto、函数长度等编码实践话题历来是社区争论焦点。
HN 评论精选
这几条评论里:质疑 2 补充 1 亲历 1
质疑为 goto 辩护:它与 break/return 本质相同,且能减少嵌套,论文立场自相矛盾
看到 goto 被当作"被污名化的语言构造"我很难受。认为 goto 是邪恶的人也应该放弃其他跳转语句:continue、break、return(还有 switch)。论文里关于 goto 的说法有矛盾之处:他们一方面说应避免深层嵌套,另一方面又说应避免 goto,而使用 goto 的好处之一恰恰是限制嵌套深度。Linux 内核编码风格文档就指出:无条件跳转更易理解、减少嵌套、避免修改时遗漏各个出口点、还能省去编译器优化冗余代码的工作。
bio_end_io_t查看英文原文
It bothers me when "goto" is assumed to be "a maligned language construct". People who think "goto" is evil should also give up the other jump statements: continue, break, and return (and also switch, though its not listed as a jump instruction in the C standard, at least not in '89 or '99). You can see some contradictions in the paper regarding goto. For example, they state that deep nesting should be avoided, but goto should be avoided as well, even though one benefit of using goto is to limit nesting depth. From the Linux Kernel coding style doc: - unconditional statements are easier to understand and follow - nesting is reduced - errors by not updating individual exit points when making modifications are prevented - saves the compiler work to optimize redundant code away ;)
质疑质疑论文数据:FreeBSD 2.0 的 LOC 统计异常,比相邻版本大 3 倍
他们统计的 FreeBSD 2.0 代码行数似乎有问题。约 600 万行,差不多是它前后两个 FreeBSD 版本的 3 倍。代码量本应平稳增长,但直到 FreeBSD 5 才再次出现这么大的规模,所以那里似乎有些不对劲。
drewg123查看英文原文
There seems to be an oddity with their LOC for FreeBSD 2.0. At ~6M LOC, it is roughly 3x the size of the FreeBSD releases just before and just after it. The size steadily creeps up, but we don't see anything else that big until FreeBSD 5, so there seems to be something fishy there..
补充补充资料:推荐 NASA 的安全关键 C 代码十条规则
作为写好 C 代码的基础指南,这篇对我帮助很大:NASA 的《The Power of 10:安全关键代码开发规则》(维基百科条目)。
badrabbit查看英文原文
This helped me out a lot as a base guidline for writing good C code: https://en.wikipedia.org/wiki/The_Power_of_10:_Rules_for_Developing_Safety-Critical_Code
亲历感慨:几十年过去技术栈几乎没变,但年轻一代代码质量明显更好
最近去大学接学计算机的儿子,他把台式机的 Win 10 换成了 Ubuntu,正在用 C++ 写一个相当复杂的程序,做 AI/ML 的底层原语。我心想我都老了,可当年在同一所大学时我写的也是 Unix(Ultrix、OSF 或 Solaris)上的 C++。我们怎么还没往前走?不过他的代码写得真漂亮,我的肯定很丑。现在的孩子比我们 30 年前写得好多了,我特别自豪。
jacksmith21006查看英文原文
I went to pick up my son at University studying CS recently. He had replaced Win 10 on his tower with Ubuntu and was writing a pretty complex program in C++. Doing some AI/ML primitives. Thought to myself I am old yet went to the same University and would have been coding in C++ on Unix (Ultrix or OSF or Solaris) at that point in my life. How in the world have we not moved on? BTW, his code was so, so pretty. Mine would have been ugly. Kids are far better coders than we were 30 years ago. I was crazy proud.
相关资源
从这篇论文所有 HN 讨论帖的全部评论里整理出来的链接。
历次讨论
- 2018Hacker News 讨论帖229 分 · 124 评
同领域还值得读
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 分钟编辑精选