编程与软件工程jonathanwhiting.com
为什么我用 C(没错,C)写游戏
Why I Write Games in C (yes, C)
2016 — 2019,它一次次回到首页
黑点是上首页(≥ 50 分)的那次投稿,空心点是没冲上去的投稿,点越大分数越高。
导读
游戏开发者 Jonathan Whiting 解释他为什么坚持用 C 语言写游戏:C 编译快、简单可控、没有 GC 停顿问题,而 C++ 复杂度高且充满他不想要的特性。文章在 2016 和 2019 两次登上 HN 首页,引发了关于游戏开发中语言选择的经典争论。
为什么经久不衰:它代表了游戏开发中'简单语言 + 手动内存管理'这一经久不衰的流派(与 Handmade Hero 等一脉相承),无论你认同与否,都是理解性能敏感场景下语言取舍的好切入点。
HN 评论精选
质疑'游戏不能用 GC'的论断缺乏量化的延迟预算分析
游戏程序员总说'GC 不行,停顿世界你承受不起',却从不说明自己的延迟预算到底是多少。144fps 下每帧有 7ms,如果 GC 只需 200 微秒,每帧跑一次也只占帧预算的 3%。我不是说该每帧跑 GC,而是'GC 在游戏引擎里行不通'这个论断从来没人给出量化依据,这让人很沮丧。
zemo查看英文原文
> The stop-the-world garbage collection is a big pain for games, stopping the world is something you can't really afford to do. I love this opinion from games programmers because they never qualify it and talk about what their latency budgets are and what they do in lieu of a garbage collector. They just hand wave and say "GC can't work". The reality is you still have to free resources, so it's not like the garbage collector is doing work that doesn't need to be done. What latency budgets are you working with? How often do you do work to free resources? What are the latency requirements there? Even at 144 fps, that's 7ms per frame. If you have a garbage collector that runs in 200us, you could run a GC on every single frame and use less than 3% of your frame budget on the GC pause. I'm -not- suggesting that running a GC on every frame is a good idea or that it should be done, but what I find so deeply frustrating is that the argument that GC can't work in a game engine is never qualified. edit: wow for once the replies are actually good, very pleased with this discussion.
用 C 或'无 OOP 的 C++'写游戏在业界有真实且增长的实践群体
作者的观点不常见但并非孤例。Handmade Hero、raylib 等项目都在走类似路线;我自己用 C++ 写游戏和引擎但完全不用 OOP 特性,认识不少专业开发者甚至 50 人规模的工作室也这么做,有些人在 OOP 上失望多年后回归了过程式 C。新手害怕手动内存管理和指针,但其实有简单的方法避免踩坑。
stephc_int13查看英文原文
The author's opinion is uncommon but not unique. A few examples: https://handmadehero.org/ https://ourmachinery.com/post/physical-design/ Simple libs widely used in game dev circles: https://github.com/nothings/stb This one is a full game engine with tools made for educational purpose: https://www.raylib.com/ I do write games and game engine code and tools in C++ without using any of the OOP features. I know quite a few of other professional, experienced and talented developers doing the same, even full AA studios with up to 50 employees. Some of them are going back to procedural C after a few years of disappointment with OOP madness. I'll publish articles about this later, but for now, all I have to say is that it just works. Newbies are often afraid of manual memory management and pointers, but there are simple ways to avoid shooting yourself in the feet with those.
文章的论据本质是个人偏好,缺乏普遍说服力
所以……本质上就是'我熟悉而且喜欢 C'。这当然很好!但正如作者所说,这对其他人来说并没有什么参考价值。
petke查看英文原文
You don't really get rid of complexity by using a simple language. You just move the complexity into your own code. Say if your language doesn't have dynamically sized containers, you will end up writing your own. You hack it so you can store different types in it. You have reinvented polymorphism. And then you need sort functions, and everything else that is missing from the language. And it wont be simple any more. Probably slow and buggy too. But you are not alone. Everyone has their own private code framework that is too complicated for anyone else to make use of. If only there was some way to avoid this mess ...
简单语言的代价是复杂性转移到用户自己的代码中
用简单的语言并不能消除复杂性,你只是把复杂性搬进了自己的代码。语言没有动态容器,你就自己写一个,为了存不同类型还要 hack,等于重新发明了多态;然后还需要排序函数和其他缺失的东西。结果它不再简单,可能又慢又有 bug,而且每个人都有自己一套别人没法用的私有框架。
hellofunk查看英文原文
>Even more than that I care about the speed of the compiler. I am not a zen master of focus, and waiting 10+ seconds is wasteful, yes, but more importantly it breaks my flow. I flick over to Twitter and suddenly 5+ minutes are gone. Quick suggestion, has really helped me: take that 10 or 20 seconds waiting for compilation, and stare out a window. This gives your eyes much needed break from focusing on a computer monitor, allows the muscles to refocus and breathe, and doing this regularly during a coding session can have important long-term benefits for your vision.
历次讨论
同类还值得读
开源应用架构
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编辑精选