HN 精选

Stop Writing Classes

Next Day Video
8 人推荐 · 跨 8 个月 · 2012–2025
脚本与动态语言(Python、Ruby 等)软件架构与系统设计
Stop Writing Classes

中文导读

Jack Diederich 在 PyCon 2012 上的重磅分享《Stop Writing Classes》。通过重构真实代码,无情拆解那些徒增复杂度的类、自定义异常与冗余模块,确立了那句名言:“如果一个类只有两个方法,且其中一个是 __init__,那它本就该是个函数”。

为什么 HN 推它

HN 反复推崇的“反过度抽象”代表作,很多工程师直言这个演讲彻底颠覆并净化了自己的编码风格。

「Jack Diederich 的《Stop Writing Classes》堪称经典:虽然讲的是 Python,但这一洞察对几乎所有现代语言都适用。」HN 网友原话:Jack Diederich has a great video called Stop Writing Classes: It's about Python, but the observation can apply to several languages.
英文原摘要(HackerTube / Claude 整理)

Jack Diederich's PyCon 2012 talk argues that classes are overused in Python and walks through real code, refactoring away unnecessary classes, exceptions and modules. It popularized the heuristic that a class with two methods, one being __init__, should be a function.

HN returns to it repeatedly as the canonical argument for simplicity and against premature abstraction, and several commenters say it changed how they write code.

HN 上的提及

strong_rec inglesp · 2012-10 · HN 原文
You can (and should!) watch it online here
reference krosaen · 2013-01 · HN 原文
Stop writing classes" from PyCon
rec gingerlime · 2013-04 · HN 原文
I also really liked Jack Diederich's talk "stop writing classes" at PyCon 2012
reference simon_weber · 2014-04 · HN 原文
The signature of 'this shouldn't be a class' is that it has two methods, one of which is __init__." [0]
strong_rec Vaskivo · 2014-12 · HN 原文
Then I saw the video above, and all fell into place.

相关视频