The Pragmatic Engineer - 软件设计的哲学——约翰·奥斯滕霍特 封面

软件设计的哲学——约翰·奥斯滕霍特

The Philosophy of Software Design – with John Ousterhout

本集简介

由我们的合作伙伴支持 •⁠ CodeRabbit⁠⁠ — 将代码审查时间和缺陷减少一半。使用代码优惠码 PRAGMATIC 获取一个月免费。 •⁠ Modal⁠ — 用于构建 AI 应用的云平台。 — AI 工具将如何改变软件工程?像 Cursor、Windsurf 和 Copilot 这样的工具在自动补全、生成测试和文档方面越来越出色。但当谈到软件设计时,究竟发生了什么变化? 斯坦福大学教授 John Ousterhout 认为变化不大。事实上,他认为随着 AI 工具在生成代码方面能力增强,优秀的软件设计反而变得更加重要。 在本期《实用工程师》节目中,John 与我探讨了为何设计依然重要,以及为何大多数团队难以做好设计。我们深入探讨了他的著作《软件设计哲学》,剖析了自上而下与自下而上两种设计方法的差异,并探讨了为何 John 认为一些流行建议——如编写短方法或过度依赖 TDD——并不成立。 我们还探讨了: • 工业界与学术界工作的差异 • 为何 John 认为随着 AI 能力增强,软件设计将变得更加重要 • 自上而下与自下而上的设计方法——以及为何你应该同时使用两者 • John 的“设计两次”原则 • 为何深度模块对良好软件设计至关重要 • 特殊情况与异常处理的最佳实践 • 设计思维中被低估的同理心特质 • 为何 John 主张提前进行一些设计 • John 对单一职责原则和 TDD 的批评,以及他为何推崇写得好的注释 • 还有更多! 一个有趣的事实:当我们录制本节目时,John 正在为 Linux 内核做贡献:为 Homa 传输协议添加支持——该协议由他的博士生发明。John 希望让这一协议得到更广泛的应用,因此正投入大量工作实现这一目标。真是一位传奇人物!(我们此前曾探讨过 Linux 是如何构建的,以及如何为 Linux 内核做贡献) — 时间戳 (00:00) 引言 (02:00) John 为何重返学术界 (03:47) 学术界与工业界的工作差异 (07:20) 战术龙卷风 vs. 10x 工程师 (11:59) AI 辅助编码的长期影响 (14:24) 软件设计概览 (15:28) 为何 TDD 和设计模式如今不再流行 (17:04) 软件设计的两种通用方法 (18:56) 应对复杂性的两种方式 (19:56) 为何不要轻易采纳第一个想法 (23:24) Uber 如何使用设计文档 (26:44) 深度模块 vs. 浅层模块 (28:25) 错误处理的最佳实践 (33:31) 同理心在设计过程中的作用 (36:15) John 如何进行设计评审 (38:10) 线下规划与使用传统白板的价值 (39:50) 如何引导规划讨论,以及最适合的场景 (42:20) 提前进行部分设计的价值 (46:12) John 为何撰写《软件设计哲学》 (48:40) John 在斯坦福的课程概览 (52:20) Gergely 职业早期的一个艰难教训 (55:48) John 为何不同意 Robert Martin 关于短方法的观点 (1:10:40) John 在 Linux 内核中的当前编码项目 (1:14:13) 《软件设计哲学》第二版的更新内容 (1:19:12) 快速问答环节 (1:01:08) John 对 TDD 的批评及他更推崇的做法 (1:05:30) John 为何支持使用注释,以及如何正确使用 (1:09:20) John 如何使用 ChatGPT 解释 Linux 内核中的代码 — 本期相关内容的《实用工程师》深度文章: • 使用 RFC、设计文档和 ADR 进行工程规划 • 偿还技术债务 • 软件架构师类型 • 构建 Bluesky:一个分布式社交网络 — 查看本集的完整文字稿及其他参考资料:⁠⁠https://newsletter.pragmaticengineer.com/podcast⁠⁠ — 制作与营销由 ⁠⁠⁠⁠⁠⁠⁠⁠https://penname.co/⁠⁠⁠⁠⁠⁠⁠⁠ 负责。如有关于赞助本播客的咨询,请发送邮件至 podcast@pragmaticengineer.com。 立即订阅《实用工程师》获取完整内容:newsletter.pragmaticengineer.com/subscribe

双语字幕

仅展示文本字幕,不包含中文音频;想边听边看,请使用 Bayt 播客 App。

Speaker 0

现在,AI和大语言模型工具正在迅猛发展。

Right now, there's a huge explosion of AI and LLM tools.

Speaker 0

这会对软件工程带来什么改变?

How might this change software engineering?

Speaker 1

有些事情比较明确,有些则还不太清楚。

There's things that seem relatively clear and things that seem less clear.

Speaker 1

我觉得比较明确的一点是,AI工具会让编写底层代码变得更容易。

I think on the relatively clear side is that the AI tools will make it easier to churn out low level code.

Speaker 1

就像你所说的,代码自动补全。

As you call it, autocomplete.

Speaker 1

自动补全的功能会越来越强大。

Autocomplete will get better and better.

Speaker 1

它生成的代码质量实际上可能相当不错。

It could actually be reasonably high quality code that gets turned out.

Speaker 1

所以看起来,这种情况很可能会发生。

So it seems like that will probably happen.

Speaker 1

那关键的问题就是,AI工具能在多大程度上真正取代高层次的设计工作?

Then the big question is, to what degree can the AI tools actually replace the higher level design tasks?

Speaker 1

这个我还没法回答。

I don't know the answer to that.

Speaker 1

到目前为止,我看现有的工具还没办法做到这一点。

So far, I don't see anything in the current tools that makes me think they're going to do that.

Speaker 1

但我觉得有意思的是,随着AI越来越多地承担底层编程任务,软件设计师的工作重心会越来越偏向于设计本身。

But what's interesting about this, I think, is that by handling more and more of the low level programming tasks, what software designers do is going to be more and more design.

Speaker 1

我认为软件设计的重要性会越来越高。

I think software design is going to become more and more important.

Speaker 1

开发者花在设计上的时间会越来越多,可偏偏我们大学里根本没人教软件设计,这真是挺遗憾的。

That'll be a larger and larger fraction of where developers spend their time, which makes it even more sad that we don't really teach software design in our universities at all.

Speaker 0

约翰·奥斯垂特是《软件设计哲学》的作者,目前是斯坦福大学的计算机科学教授。

John Ousterhout is the author of A Philosophy of Software Design and currently a professor of computer science at Stanford.

Speaker 0

约翰·科尔创办过两家科技公司,曾在一些微系统公司工作,开发过一种T细胞脚本语言,还发明了一种RAFT共识算法,被MongoDB、CockroachDB、Kafka等众多数据库和系统广泛采用。

John Cole founded two tech companies, worked at some microsystems, created a T cell scripting language, and invented a RAF consensus algorithm that is used across databases and systems like MongoDB, CockroachDB, Kafka and others.

Speaker 0

在我们的对话中,我们探讨了人工智能对软件工程的影响,以及为什么软件设计的重要性比以往更突出;还有什么是深层模块和浅层模块,为什么深层模块对应对软件复杂性至关重要。

In our conversation we cover: The impact of AI on software engineering and why software design could become more important than before The concept of deep and shallow modules and why deep modules are so important to deal with complexity in software.

Speaker 0

约翰还分享了关于错误处理、代码注释的建议,以及他为什么建议避免测试驱动开发,还有很多其他话题。

John's advice on error handling, commenting, and why he suggests avoiding test driven development and many more topics.

Speaker 0

如果你对实用的软件设计方法和策略感兴趣,想从具体的编码中抽身出来,好好思考设计本身,这一期节目非常适合你。

If you're interested in practical software design tactics and strategies and want to take a step back from tactical coding, this episode is for you.

Speaker 0

如果你喜欢这个节目,请在任意播客平台或YouTube上订阅我们的频道。

If you enjoy the show, please subscribe to the podcast on any podcast platform and on YouTube.

Speaker 0

欢迎收听本节目。

Welcome to the podcast.

Speaker 1

谢谢。

Thank you.

Speaker 1

很高兴能来到这里。

I'm excited to be here.

Speaker 0

你在斯坦福大学从事学术工作已经很久了,但之前你一直在业界工作。

You have been working in academia at Stanford for quite a while, but you were in the industry beforehand.

Speaker 0

你是怎么从科技公司创业,转到学术界的呢?

What made you change from working at tech companies from founding your own companies to to academia?

Speaker 0

说真的,你当时为什么做出这个决定?

And, you know, why did you do it?

Speaker 1

我一直都想兼顾学术和工业界的工作。

I've always wanted to do both academia and industry.

Speaker 1

我拿到博士学位时,一直在纠结该选哪条路,因为我既喜欢学术的自由创造,也热爱教学。

When I got my PhD, I debated what to do because I love the creative freedom of academia and I love teaching also.

Speaker 1

但我也非常享受开发真实软件的过程。

But I also love building real software.

Speaker 1

编程是我生活中最重要的热情之一。

Coding is one of the passions that I live for in my life.

Speaker 1

所以我一直觉得,我这一生大概会同时做这两件事。

And so I always kind of figured I'd probably do both over my career.

Speaker 1

拿到博士时,别人给我的建议是,如果想兼顾两者,最好先做学术,因为从学术转到工业界比反过来容易得多。

When I got my PhD, the advice I was given was if you're going to do both, it's always better to do academia first because it's easier to switch from academia to industry than the other way around.

Speaker 1

所以我去了伯克利,在那里度过了非常充实的十四年,但随着时间推移,想开发商业软件的念头越来越强烈,最后我决定放手一搏。

So I went to Berkeley, had a fabulous fourteen years there, but over time this nagging field for wanting to build commercial software had built up and so I finally decided to take the plunge.

Speaker 1

我辞掉了伯克利的职位,搬到硅谷,在太阳公司待了几年,创办了两三家不算特别成功的公司,那段经历特别精彩。

I gave up my position at Berkeley, moved to Silicon Valley, worked at Sun for a few years, started a couple of only moderately successful companies and had a great time doing that.

Speaker 1

创业期间我学到了太多东西。

Just learned a ton of stuff doing startups.

Speaker 1

但随着时间推移,工业界的召唤又在我心里慢慢浮现,我逐渐意识到,虽然创业很有趣,但当教授才是我真正热爱的事业。

But over time the nagging of the call of industry kind of built up in me and I gradually realized, although I liked doing startups, that I think being a professor is my real sort of true passion in life.

Speaker 1

在创业十四年后,我很幸运地获得了斯坦福的职位,之后又在斯坦福度过了十五年左右,过得非常开心。

So after doing startups for fourteen years, I was fortunate enough to get a position at Stanford and then I've had another fourteen or fifteen years back at Stanford where I've been really happy.

Speaker 1

能亲身体验这两个世界,真的特别有意思。

So it's been really fun, really fun getting to see both sides.

Speaker 1

说实话,我觉得同时经历这两者,反而让我在两边都做得更好。

And honestly, think, you know, doing both has actually made me better at both.

Speaker 0

你看到很多只在业界工作的人,他们或许也在考虑有朝一日转向学术界,你怎么看?

What do you see, I talk with a lot of people obviously who are only in the industry and maybe they're thinking of one day doing academia.

Speaker 0

我其实也曾经想过这件事。

I I I at some point thought of this myself.

Speaker 0

我父亲以前是大学老师。

My my my dad is his university teacher, was university teacher.

Speaker 0

当然,学术界也有不少人。

And obviously, there's people in academia.

Speaker 0

你同时接触过这两边,那科技行业和学术界之间最大的区别是什么?

Having them both, what what are big differences between, you know, as we call it the tech world, which is industry and academia?

Speaker 1

其实,当我进入行业时,发现两者没我想象中那么不同。

Well, first it wasn't as different as I thought it was going to be when I went to industry.

Speaker 1

不管是做初创公司,还是在其他地方,你都是和一个小团队合作,试图做些全新的东西,开发真正能用的软件。

In both cases you're, well, it's probably doing startups, because in both cases you're working with a relatively small team, you're trying to do something relatively new, trying to build software that really works.

Speaker 1

即使在学术界的时候,我们也努力做出真正能用的东西,而不是只做一次性研究原型。

Even when I was in academia, we tried to build stuff that really works, not just throw away research prototypes.

Speaker 1

所以从很多方面来看,它们并没有太大差别。

So in many ways it wasn't that different.

Speaker 1

但在其他方面,确实不一样。

But in other ways it was.

Speaker 1

你得跟更广泛的人打交道,比如销售、市场、金融和风险投资的人。

And that you deal with a much broader spectrum of people, you know, sales people and marketing people and financers and venture capitalists.

Speaker 1

这点挺有意思的,能接触到形形色色的人。

That was one of the fun things about it, is seeing a much greater diversity of people.

Speaker 1

我觉得让我回到学术界的一个关键原因,是行业里——尤其是初创公司——压力特别大,总得把自己吹得比实际更厉害。

I would say the difference that contributed to my going back to academia, I would say one of the downsides of industry, is that there's tremendous pressure in startups particularly to make yourself look bigger and better than you are.

Speaker 1

你得活下去,要融资,所以难免要包装公司、夸大其词、自我营销。

You're trying to survive and get funding and so there's a lot of pressure to spin your company and exaggerate and market yourself.

Speaker 1

其实大家都多多少少会这样。

I mean everybody does it to some degrees.

Speaker 1

有些人做得太过火,甚至违法,结果惹上麻烦。

Some people do it in ways so extreme it's illegal, they get in trouble.

Speaker 1

但这种事让我挺不舒服的。

But that kind of bothered me.

Speaker 1

在我们公司内部,当然我们对外也要做宣传,但内部我们一直力求诚实。

And within my companies, of course we had to market ourselves externally, but internally we tried to be very honest.

Speaker 1

我不希望听到任何内部谎言或夸大其词,因为那样会把公司置于危险之中。

And we're not going to I don't want to hear lies and spinning internally because that puts our company at risk if you do that.

Speaker 1

但我喜欢学术界的一点是,你做项目,有的成功,有的失败。

But nonetheless, the thing I like about academia is you do a project, some of them work, some of them don't.

Speaker 1

如果项目没成功,你就说:哎呀,看来这个想法不太行,原因在这儿,然后接着做下一个。

If a project doesn't work, you just say, oops, okay, that wasn't a good idea, here's why, and you go on to the next thing.

Speaker 1

但在公司里,要是项目没成,你总不能说:哎呀,搞砸了,抱歉大家,我们明天就关门。

In a company, if it's not working, you can't really say, oops, that didn't work, sorry everybody, we're shutting down tomorrow.

Speaker 1

你总得想办法绕过去,硬撑着继续。

You try and somehow figure some way around it.

Speaker 1

所以我觉得,这就是我对行业最不喜欢的一点。

So I think that was the thing, the one thing about industry that I liked least.

Speaker 0

本集由CodeRabbit赞助播出,这是一款AI代码审查平台,帮助工程团队在不牺牲代码质量的前提下加速开发。

This episode was brought to you by CodeRabbit, the AI code review platform transforming how engineering teams shift faster without sacrificing code quality.

Speaker 0

代码审查很重要,但很耗时。

Code reviews are critical but time consuming.

Speaker 0

CodeRabbit 就像你的 AI 助手,能即时给出每份拉取请求的审查意见和潜在影响。

CodeRabbit acts as your AI Copilot providing instant code review comments and potential impacts of every pull request.

Speaker 0

它不只是指出问题,还能一键提供修复方案,支持你用 AST 图形模式自定义代码质量规则,捕捉传统静态分析工具容易漏掉的问题。

Beyond just flagging issues, CodeRabbit provides one click fix solutions and lets you define custom code quality rules using AST graph patterns, catching several issues that traditional static analysis tools might miss.

Speaker 0

CodeRabbit 已经审查了超过五百多万个拉取请求,部署在一百万个仓库中,被五万个开源项目使用。

CodeRabbit has so far reviewed more than 5,000,000 pull requests, is installed in 1,000,000 repositories, and is used by 50,000 open source projects.

Speaker 0

前往 coderabbit.ai 免费试用一个月,使用优惠码 pragmatic。

Try CodeRabbit free for one month at coderabbit.ai using the code pragmatic.

Speaker 0

就是 coderabbit.ai,别忘了用 pragmatic 这个优惠码。

That is coderabbit.ai and use the code pragmatic.

Speaker 0

本集由 Modal 携带,这是一个让 AI 开发变得简单的云平台。

This episode is brought to you by Modal, the cloud platform that makes AI development simple.

Speaker 0

想要 GPU,又不想折腾?

Need GPUs without the headache?

Speaker 0

用 Modal,只需在任何 Python 函数里加一行代码,它就能立刻在云端运行,CPU 或 GPU 随你选。

With Modal, just add one line of code to any Python function and boom, it's running in the cloud on your choice of CPU or GPU.

Speaker 0

最棒的是,你只为你实际使用的资源付费。

And the best part, you only pay for what you use.

Speaker 0

容器启动快到亚秒级,还能瞬间扩展到数千个 GPU,难怪 Suno、Ramp 和 Substack 这些公司都信赖 Modal 来运行他们的 AI 应用。

With sub second container starts and instant scaling to thousands of GPUs, it's no wonder companies like Suno, Ramp and Substack already trust Modal for their AI applications.

Speaker 0

想用 H100?只要 pip install 一下就行。

Getting an H100 is just a PIP install away.

Speaker 0

访问 modal.com/pragmatic,每月免费领取 30 美元的信用额度。

Go to modal.com/pragmatic to get $30 in free credits every month.

Speaker 0

就是 modal.com/pragmatic。

That is modal.com/pragmatic.

Speaker 0

你知道的,你之前在学术界工作过,还教过一门课,这个我们待会儿再聊,但你写了《软件设计的哲学》这本书,我接触的很多科技圈人士都说,这是他们读过最实用的一本,能给出具体可操作的建议,教人怎么思考软件设计。

Now, you know, thanks to you having worked in academia as well and you taught a course, which which we'll later talk about, but but you wrote this book, The Philosophy of Software Design, and a lot of people in the tech world who I talk with point to this book as one of the best books that that gives them specific actionable things, ways to think about software design.

Speaker 0

我想聊聊书里的一些内容。

I just want to go go into some of the things into the book.

Speaker 0

读过这本书的人会觉得耳目一新,没读过的人则会发现,这本书提出了很多全新的观点。

People who've read it will find this refreshing, and people who haven't, Mindfight is new ideas.

Speaker 0

书的开头,大概第二或第三章,前十几页里,你提到了一个叫‘战术龙卷风’的概念。

In the very beginning of the book, in chapter, I think, two or three in in in the first, like, 10 or 15 pages, you write about something called tactical tornadoes.

Speaker 0

让我引述一小段原文。

And let me just quote a little bit from from from from this.

Speaker 0

你写道:‘战术龙卷风’是指那些写代码速度远超常人,但完全靠临时应对方式开发的程序员。

You wrote, a tactical tornado is a prolific programmer who who pumps out code faster than other works, but does it in totally tactical fashion.

Speaker 0

要赶一个紧急功能,没人比‘战术龙卷风’更快。

When it comes to implementing a quick feature, nobody gets it done faster than a tactical tornado.

Speaker 0

在一些公司里,管理层把‘战术龙卷风’当成英雄来推崇。

In some organizations, management's trees, tactical tornadoes as heroes.

Speaker 0

但问题是,‘战术龙卷风’留下一地狼藉,通常还得其他工程师来收拾烂摊子。

However, tactical tornadoes leave a wave of destruction behind, and typically other engineers must clean up the messes left by this tactical tornado.

Speaker 0

所以我第一个想问你,你是怎么遇到你的第一个‘战术龙卷风’的?

So I I wanted to ask you, first of all, how did you come across your first tactical tornado?

Speaker 0

那你觉得,为什么这类人还在大多数公司里存在呢?

And why do you think these types of folks are still around in most companies?

Speaker 0

因为我曾经突然意识到,哦对,我也见过这种战术龙卷风。

Because I had an moment when I was like, oh yeah, I know the tactical tornadoes as well.

Speaker 1

我没法说出具体哪件事或哪个人,而且我也不想点名。

I can't point to a specific incident or a person, and I wouldn't want to identify them anyway,

Speaker 0

但是

but

Speaker 1

我职业生涯中确实遇到过这种人。

I've encountered them over my career.

Speaker 1

我敢打赌,每个有丰富软件开发经验的人,都遇到过这种人,也都能体会到其中的挫败感。

I bet everybody who has significant software development experience has encountered these people over your career and just kind of observing them the frustration with that.

Speaker 1

我觉得,这其实就是一种特定的性格类型。

You know, I think it's just a particular personality type.

Speaker 1

有些人特别注重细节,属于那种喜欢收尾的人,一定要把每件事都做到完美,而且总能把事情做完。

There are people who are very, very detail focused and sort of closers, want to get absolutely everything right and they finish everything.

Speaker 1

有些人特别喜欢启动项目,把前80%甚至90%做得很好,但最后那10%到20%对他们来说根本不重要。这世界上有做事细致的人,也有马虎的人,所以这些战术型混乱者本质上就是比较邋遢。

And there's people who are they love getting started on projects and doing the first 80 or ninety percent, but that last 10 or 20% doesn't matter to them so much and they're not, you know, there's like there's neater people and there's sloppier people in the world, so the tactical narratives are just sort of sloppy.

Speaker 1

他们根本不在乎留下一堆烂摊子,完全不觉得有什么问题。

They don't care about leaving cruft behind, it doesn't really bother them at all.

Speaker 1

这其实就是一种性格类型。

It's just a personality type.

Speaker 1

所以我猜这种人会一直存在,尤其是当一些公司把速度看得比什么都重要时。

So I suspect they'll always be there, particularly because some organizations value speed above all else.

Speaker 0

尤其是初创公司,对吧?

Especially startups, right?

Speaker 1

对,确实很多这样。

Yeah, lot of right.

Speaker 1

有些初创公司可能全都是这种战术型混乱者。

There are startups that are probably completely staffed by tactical tornadoes.

Speaker 1

你说到

You call

Speaker 0

他们叫这些人为战术龙卷风,不过我想到一些别人常用的类似说法。

them tactical tornadoes, but like some of the synonyms that came into my mind as I was thinking of of what people use.

Speaker 0

有时候他们会说这是‘十倍工程师’,尤其是管理层看到某人做事特别快的时候。

Sometimes they use a 10x engineer, especially when management sees, oh, they just get things faster.

Speaker 0

有时候呢,就是一种赶工的做法,专指那些手速快的人;十年前可能有人管这叫‘黑客’,但那时候指的是效率高,现在这个词已经不一样了。

Sometimes they you know, like it's a hacky way of doing things for someone who just hacks quickly, or at some point, maybe a decade ago, people call it a hacker, but they in a in a way of working fast, but I I don't think we have that anymore.

Speaker 0

不过确实有很多情况,这种做法反而是正面的。

But there are a lot of cases, it is a positive thing indeed.

Speaker 0

我一开始想的也是正面意义。

Was just thinking positive initially.

Speaker 1

当我想到‘十倍工程师’,尤其是谷歌对这个词的定义时,我觉得跟战术龙卷风完全不是一回事。

When I think of 10x engineers and the way Google defined it, I don't think of these as tactical tornadoes.

Speaker 1

我想到的是那些能设计出非常简洁架构的人,用极少的代码就能实现功能。

I think of these are people who come up with the really clean designs that can be implemented in very small amounts of code.

Speaker 1

他们每天写的代码可能比别人少,但实现的功能却强得多,而且稳定性好、可扩展性强。

And so they might actually write less code per day than other people, but the functionality that they implement is way higher and it comes with higher stability and evolvability and so on.

Speaker 1

所以对我来说,这就是所谓的十倍工程师。

So to me at least, that's the 10x engineer.

Speaker 0

我同意你的看法。

I agree with you.

Speaker 0

我想补充一点,我觉得‘十倍工程师’这个说法太模糊了,每个人理解都不一样。尤其是我见过一些非技术背景的CEO,他们口中的十倍工程师其实就是那种战术型风暴——因为他们只看到产出速度。

I'll just add the note that I think the 10x engineer is so ambiguous that it means different for every person and especially so when I've when I've seen it was mostly less technical CEOs refer to my 10x engineer who was a tactical tornado because what they saw is, oh, I'm getting output.

Speaker 0

他们没说对方没在干活。

They're not saying no, they're building it.

Speaker 0

但他们根本不懂背后的技术深度,也不明白这种做法其实拖慢了其他人。

But of course, they had trouble understanding the tech depth that is going into there, how it's slowing others down.

Speaker 0

在这个环境里,你提到的那些人,可能在那些不贴近代码的人眼里,根本算不上十倍工程师。

And, you know, some of the people that you talked about in this environment might have not been perceived as a 10x engineer by the, this person who is not that close to the code.

Speaker 0

顺便说一句,我完全同意你的观点。

And I totally agree with you, by the way.

Speaker 0

这其实是个很好的提醒:一切都要看相对性,对吧?

This is probably a good reminder of everything's relative, right?

Speaker 0

一切都取决于你的视角。

Everything is based on your vantage point.

Speaker 0

如果你贴近代码,懂技术,就会看重别的东西。

If you are close to the code, you're technical, you will value other things.

Speaker 0

你确实应该看重别的东西。

You should value other things.

Speaker 1

我觉得很多问题其实归结为战略和战术的区别。

Know, think a lot of this comes down to strategic versus tactical.

Speaker 1

总有些人更看重短期成果,也有些人更注重长期影响。

Again, there are people who value all the short term stuff and there are people who value place more emphasis on the long term stuff.

Speaker 1

我对设计的理解,完全着眼于长期价值。

And my view of design is all about the long term stuff.

Speaker 1

但正如你所说,很多人只从短期角度来考虑问题。

But as you've said, there are many people who think of it all in terms of short term stuff.

Speaker 1

所以我也能理解,为什么他们对‘十倍工程师’会有不同的看法。

And so I can see how they would have a different idea of what a 10x engineer is.

Speaker 0

说到长期和短期,我重新读到‘战术龙卷风’这部分时,突然想到一件事:现在AI和大语言模型工具正爆发式增长,就像你可能已经看到的那样,它们生成代码的速度非常快,说白了,简直就是个战术龙卷风。

And speaking of long term versus short term, one thing that came to my mind reading rereading this tactical tornado part is right now there's a huge explosion of of AI and LLM tools, which are, as as as you're you're probably seeing it, they are really good at generating code rapidly, a little bit like the tactical tornado, to be honest.

Speaker 0

你只要给个提示就行。

You can prompt them.

Speaker 0

它们能写短代码,也能写长代码,能自动补全,还能生成整个框架。

They can do short, they can do long, they can do auto complete, they can do all skeletons.

Speaker 0

我想问问,根据你目前的观察,如果这些工具就这么一直发展下去——我们假设每个工程师都能随时用上这种‘战术龙卷风’,而且从不拒绝,疯狂输出代码——那它们对软件工程会带来什么长期影响?

I was wondering, so far what you've observed, what do you think the long term impact of these tools, if we assume that this is how they're going to stay, let's just assume that, every engineer will have tactical tornadoes at their fingertips and who do not say no, and they will churn out code.

Speaker 0

这会怎样改变软件工程本身?

How might this change software engineering?

Speaker 1

这是个特别有意思的问题。

That's a really interesting question.

Speaker 1

我也希望我能给出确切答案,但我真不知道,只能猜一猜。

And I wish I knew the answer, I don't, I can only guess.

Speaker 1

我觉得未来五到十年,我们肯定会看到巨大的变化,但具体会往哪个方向走,真的很难预料。

I think we're going to see big changes over the next five to ten years and it's really hard to predict what direction they're going to go.

Speaker 1

有些事情看起来比较清楚,有些则还不明朗。

What seems there's things that seem relatively clear and things that seem less clear.

Speaker 1

我觉得比较明确的是,AI工具会让生成底层代码变得更容易。

I think on the relatively clear side is that the AI tools will make it easier to churn out low level code.

Speaker 1

就像你所说的,代码自动补全。

As you call it, autocomplete.

Speaker 1

自动补全的功能会越来越强。

Autocomplete will get better and better.

Speaker 1

而且这未必只是那种临时拼凑的代码,很可能产出的是质量相当不错的代码。

And I think it won't necessarily be sort of tactical tornado stuff, it could actually be reasonably high quality code that gets turned out.

Speaker 1

所以这一点很可能会发生。

So it seems like that will probably happen.

Speaker 1

关键问题是,AI工具能在多大程度上取代更高层次的设计工作?

And the big question is, to what degree can the AI tools actually replace the higher level design tasks?

Speaker 1

这个答案,我真不知道。

And, you know, I don't know the answer to that.

Speaker 1

到目前为止,我还没看到当前这些工具有哪项能力让我觉得它们能做到这一点。

So far I don't see anything in the current tools that makes me think they're going to do that.

Speaker 1

但话说回来,千万别小看未来可能发生的变化。

But, you know, never underestimate what could happen to this.

Speaker 1

但我觉得有意思的是,随着AI越来越多地承担底层编程任务,软件设计师的工作将越来越聚焦于设计本身。

But what's interesting about this I think is that by handling more and more of the low level programming tasks what software designers do is going to be more and more design.

Speaker 1

所以我认为,软件设计的重要性会越来越高。

So I think software design is going to become more and more important.

Speaker 1

开发者花在设计上的时间占比也会越来越大。

That will be a larger and larger fraction of where developers spend their time.

Speaker 1

这也让人更觉得遗憾——我们大学里根本没怎么教软件设计。

Which makes it even more sort of sad that we don't really teach software design in our universities at all.

Speaker 1

所以我们现在教学生的技能,说不定正是会被AI工具取代的那些。

So the skills we're teaching students may actually be the skills that are going to be replaced by the AI tools.

Speaker 0

我们能不能深入聊聊软件设计这件事?

Can we just double click on software design?

Speaker 0

你如何看待软件设计?

How do you see software design?

Speaker 0

它到底是什么?为什么这么重要?

What is it, and and why is it important?

Speaker 0

我问这个问题,是因为听起来可能有点天真,但现在你真的可以靠选个模板,直接开始做应用了。

And the reason I'm asking the question, it's it's a pretty it's it it might seem like a naive question, but these days, you really can get started building an application by, you know, create taking a template, using it.

Speaker 0

很快你只要跟AI工具说一声,它就能帮你生成各种东西。

You know, you you will soon be able to prompt an AI tool that that will generate things for you.

Speaker 0

你是怎么看待软件设计的?

How do you think about software design?

Speaker 0

你知道的,它本来就是挺抽象的,对吧?

You know, it's abstract, right?

Speaker 0

本质上就是这样。

By nature.

Speaker 1

我觉得软件设计其实是个分解问题。

So, well, I think of it as it's a decomposition problem.

Speaker 1

就是如何把一个复杂庞大的系统拆分成可以相对独立开发的小模块。

It's how do you take a large complicated system and divide it up into smaller units that you can implement relatively independently.

Speaker 1

顺便说一句,我每次做演讲时都会问观众:你觉得计算机科学里最重要的理念是什么?

And by the way, to me, I often, when I give talks I often ask people, what do you think is the most important idea in all of computer science?

Speaker 1

问问现场的人。

Ask the audience.

Speaker 1

在我看来,答案就是分解。

To me, I think decomposition.

Speaker 1

这是贯穿计算机科学所有工作的核心思想。

That's the key thing that threads through everything we do in computer science.

Speaker 1

怎么把庞大复杂的问题拆解开来?

How do you take large complicated problems and break them up?

Speaker 1

这就是设计。

And that's design.

Speaker 1

而实现,就是去处理每一个单独的模块。

And then implementation is when you go about the individual pieces.

Speaker 1

当然,你还可以进一步设计,把这些部分拆得更细。

Again, you may do more design of those to break them up into still smaller pieces.

Speaker 1

这正是我理解软件设计的方式。

But that's the way I think about software design.

Speaker 0

过去几十年里,我注意到一个有趣的现象:大约二十年前,甚至更早一点,业界特别关注那些贴近软件设计的架构实践,比如测试驱动开发、架构模式之类的。

Now, interesting thing that I've noticed over the past few decades is about twenty years or so, maybe a little bit more, there was a lot of focus on architectural practices that felt closer to software design, things like TDD test driven development, architecture approaches, like architecture patterns.

Speaker 0

那时候人们管它们叫设计模式,像‘四人组’提出的工厂模式等等。

I think they were called design patterns, a gang of four, different, like, factory, etcetera patterns.

Speaker 0

但如今,这种关注似乎在减弱——至少在业界,提到这些模型和理念的人越来越少了。

However, the focus seems to be moving away, at least at least in the industry for there's fewer people referencing the these these models, these ideas.

Speaker 0

从你的观察来看,无论是学术界还是工业界,你认为为什么会发生这种变化?

From your observation, both in academia and industry, like, why do you think this this might have been?

Speaker 0

为什么十年前、二十年前我们对架构和设计这么重视,而现在却谈得少了,甚至想得也少了?

Why did we have such a big focus on architecture design topics ten or twenty years ago and maybe just we're talking about it less or maybe even thinking about it less?

Speaker 1

当然,每个领域都会有一些流行趋势,大家一时热情高涨,但过段时间就慢慢冷下来了。

Well, know, of course, there's always fads that everybody gets excited about and they gradually fade away.

Speaker 1

所以这可能也是原因之一。

So maybe that's part of it.

Speaker 1

至于你提到的那些,比如TDD和设计模式,我觉得它们并不属于设计。

Now, to me, the things you mentioned, TDD and patterns, I don't think of those as design.

Speaker 1

尤其是TDD,根本算不上设计。

Certainly not TDD.

Speaker 1

事实上,如果你真想讨论TDD,我们当然可以,但我觉得它其实是跟设计背道而驰的。

In fact, I would argue if you want to get into a TDD discussion we could have that, but it actually works against design.

Speaker 1

设计模式,那其实是设计的替代品。

Design patterns, that's an alternative to design.

Speaker 1

它不是自己去设计,而是直接拿现成的方案来用。

That is rather than designing something, you pull something off the shelf.

Speaker 1

我觉得在合适的地方,它确实有效。

And I think where it works, it works.

Speaker 1

当然,有些领域如果已有现成的模式适用,那直接用就好了。

Certainly there's areas where of course if a pattern works you should just use it.

Speaker 1

但对我来说,这仅仅涉及了我所理解的软件设计中极小的一部分。

But to me that only addresses a tiny, tiny fraction of what I think of the software design.

Speaker 1

设计远不止从六七个模式里挑一个那么简单。

There's so much more to design than just picking one of a half a dozen patterns.

Speaker 0

当你开始构建新软件,准备着手设计的时候,你会怎么入手呢?

When you're starting to, when you're building new software and you're saying, okay, I'm I'm gonna start to design.

Speaker 0

你是怎么开始设计的?

Like, how how how do you start designing?

Speaker 0

是拿纸笔坐下来画吗?

Is it a sitting down pen and paper?

Speaker 0

如果我们能聊一个具体的例子,比如你做过的一个项目,可能会更有帮助。

And if if if we can talk about something specific, I I think that could be even useful if there was a project that that you did.

Speaker 0

因为我真的很好奇你是怎么思考这个问题的。

Because I'm just really curious about your, you know, thinking.

Speaker 1

我没法给出一套设计的固定方法。

I can't give a recipe for design.

Speaker 1

真希望我能。

I wish I could.

Speaker 1

要是能按部就班地照着这些步骤来,就能做出好设计就好了。

You know, follow these steps in this order and you'll get a great design.

Speaker 1

真希望我能。

I wish I could.

Speaker 1

不过呢,大体上有两种方法,各有各的问题:一种是自上而下,一种是自下而上。

But you know, there's two general approaches, each of which has its pitfalls, is the top down approach and the bottom up approach.

Speaker 1

我注意到,尤其是经验少的工程师,或者对领域不熟悉的人,往往会选择自下而上。

I think what people tend to use, particularly less experienced engineers or people who are in a domain that they're not familiar with, is you do bottom up.

Speaker 1

他们会想:好吧,这个系统里我得有这个功能。

You just say, Okay, I'm going to need this functionality in this system.

Speaker 1

虽然完全不知道整个系统长什么样,但至少先把这个模块做出来。

I have no idea what the overall system is going look like, but I need this piece, so I'll just build this piece.

Speaker 1

然后挑下一个模块,再做,再做,慢慢试着把它们拼起来,一层一层地把设计搭起来。

And then you pick another piece and you build it, you pick it up, then you start trying to put the pieces together and you gradually layer in your design.

Speaker 1

这就是自下而上的方法。

So that's the bottom up approach.

Speaker 1

自上而下的方法是从整体出发,把系统拆分成你认为相对独立的模块,再逐层分解,直到能具体设计为止。

The top down approach is you start at the top and you try and break the system up into what you think are relatively independent components and then decompose those until you eventually get something that you can design.

Speaker 1

我个人觉得,顺便说一下,上世纪70年代我读研的时候,大家就一直在争论该用自上而下还是自下而上的设计方式,争论得很激烈。

My personal and by the way, in the 1970s, back when I was in graduate school, was a big discussion about should you design top down or bottom up and people argued about it.

Speaker 1

我个人的看法是,纯粹用哪一种都很困难,实际的设计过程往往是两种方式的结合:你先考虑大块结构,再琢磨一些细节,动手做点东西,结果发现不太行,就推倒重来,再做新的。

My personal opinion is that it's hard to do either one pure, that the actual process design is some combination where you think about big pieces and then you start thinking about some little pieces and you build some stuff and you discover it actually didn't work very well, you throw it away and you build some more stuff.

Speaker 1

这其实是一个不断来回迭代的过程。

And it's this iterative kind of back and forth process.

Speaker 0

你提到这两种方式挺有意思,因为书里一开始就说,设计的核心就是管理复杂性,然后你引出了这两种方法。

And it's interesting that you mentioned the two ways because in the book, the book itself starts with you writing how designing is all about managing complexity, and then you bring these two approaches.

Speaker 0

那这两种应对复杂性的方法分别是什么?

What were the two approaches to complexity?

Speaker 1

一种是,设计中有些做法能直接彻底消除复杂性。

So one is that there are certain things you can do with design that simply eliminate complexity completely.

Speaker 1

避免处理那些特殊情况之类的问题。

Eliminating working on special cases and things like that.

Speaker 1

所以这些是最棒、最有效的方法。

So those are the best, most powerful approaches.

Speaker 1

但你不可能把所有复杂性都消除掉。

But you can't eliminate all complexity.

Speaker 1

这时候第二种方法就是采用模块化设计,本质上是把复杂性隐藏起来。

So then the second approach is where you use modular design, where you basically try and hide the complexity.

Speaker 1

也就是说,把那些相对复杂的东西隔离到一边,让专人去解决这些问题、处理这些复杂性,系统里的其他人完全不需要关心这些。

That is, you take things that are relatively complicated and put them off to the side where somebody can solve this problem and deal with this complexity and nobody else in the system has to be aware of that complexity.

Speaker 1

所以,这就是应对复杂性的两种主要方式。

So those were the two overall ways of dealing with complexity.

Speaker 0

对。

Yeah.

Speaker 0

好的软件设计能帮我们更好地掌控复杂性。

And good software designed will help us deal like wrangle complexity.

Speaker 0

对吧?

Right?

Speaker 0

我感觉这正是你所说的其中一个方面,对吧?

Do do I sense that that's that's one of the It

Speaker 1

这两种方法都能做到。

will do with both of those.

Speaker 1

它不仅能帮你找到消除复杂性的方式,还能教你如何模块化,让大多数人不必了解大部分复杂性。

It will both give you ideas for how to eliminate it and also for how to, again, modularize it so most people don't have to be aware of most of the complexity.

Speaker 0

书中有一个让我特别有共鸣的观点,就是值得把东西设计两遍。

One interesting idea that I it resonated with in the book is is you wrote about how it's worth designing things twice.

Speaker 0

事实上,书中专门有一章讲这个,第十一章。

In fact, this is a whole chapter in the book, chapter 11.

Speaker 0

这一章的名字就叫‘设计两遍’。

It's it's called designing it twice.

Speaker 0

你还引用了自己的一段话。

And you wrote a quote from you.

Speaker 0

可惜的是,我经常看到一些很聪明的人,一有想法就马上动手做,结果反而没能发挥出他们真正的实力。

Unfortunately, I often see smart people who insist implementing the first idea that comes to mind, and this causes them to underperform their true potential.

Speaker 0

这也让他们很难合作。

It also makes them frustrating to work with.

Speaker 0

你是怎么注意到这一点的?

How did you come across this this observation?

Speaker 0

你还提到一点,其实重新设计一次,并不会比大多数人想的花更多时间。

And one more thing that you added is it doesn't take more time to design twice than what what most people think.

Speaker 1

是的,我之所以发现这一点,是因为我曾在斯坦福和伯克利都当过教授,这两所大学都是全球顶尖学府,招来的研究生都非常优秀。

Yeah, so first, the way I came across this is because I've been a professor at both Stanford and Berkeley, which are two of the top universities in the world and both places get brilliant graduate students.

Speaker 1

我注意到,这两所学校的很多学生都有不好的工作习惯。

And I've noticed it's common for students at both places to have bad work habits.

Speaker 1

原因在于,他们从小到大,什么事都太顺了。

And the reason is, all their lives everything's always been easy for them.

Speaker 1

他们一直以来都是在所有事情上表现最出色的那一个。

They've always been the best at everything they did.

Speaker 1

他们在高中时比老师还聪明,上大学后可能跟教授一样聪明,成绩总是名列前茅。

In high school they were smarter than their teachers, in college perhaps as smart as their professors, top of their class.

Speaker 1

他们脑子里冒出来的第一个想法,往往就足够拿高分了。

Their first ideas, just the first thing that came off their mind was always good enough to get great grades.

Speaker 1

所以他们从来没什么动力去反复思考。

And so there's never been any real incentive for them to think twice.

Speaker 1

渐渐地,他们就开始相信,只要是我想到的,肯定差不了。

And I think they start kind of latching on to the idea that whatever comes to my mind is going to be good.

Speaker 1

但你知道,问题越难,这种想法就越行不通。

But you know, as you get into harder and harder problems, that characteristic goes away.

Speaker 1

尤其是在顶尖大学做研究时,说实话,我们面对的都是特别难的问题。

Particularly when we're doing research at top universities, honestly we're working on really hard problems.

Speaker 1

没人第一次想到的点子就是最好的。

Nobody's first idea is going to be the best idea.

Speaker 1

所以我经常得督促学生,逼他们多动脑筋。

And so I often have to work with students to force them to think about things.

Speaker 1

所以,举个例子,我常用的一个方法是说:假设我告诉你,你刚提出的这个方案不能实现。

And so for example, a common technique I will use is I will say, Suppose I told you that you may not implement this thing you just suggested.

Speaker 1

如果你硬要这么做,我就停掉你的经费,直接让你退学。

And if you try and do it, I'm going to stop funding you and have you thrown out as a grad student.

Speaker 1

那你的备选方案是什么?

What would be your second approach?

Speaker 1

你会想出别的办法,还是说:算了,我还是换个导师吧?

Would you come up with something or would you say, Okay, I better look for a new advisor.

Speaker 1

有意思的是,我通常这么说,是因为我觉得有更好的做法。当我逼他们先停下来,过一阵再回来,第二个想法总是更好。

And the interesting thing is and by the way, I say this typically when I think there's a better way of doing it and when I force and they go away and come back, the second idea is always better.

Speaker 1

真的更好。

It's better.

Speaker 1

我自己也多次见证过这种情况。

And I've seen this myself.

Speaker 1

我整个职业生涯中最典型的例子,就是我设计TK工具包的时候,那是TKL系统的一部分。

The best example I can think of over my whole career was when I was designing the TK Toolkit, which is a part of the TKL, TK system.

Speaker 1

我当时在琢磨,图形控件的编程接口应该怎么设计。

And I was trying to figure out what should be the API for programming graphical widgets.

Speaker 1

其实那段时间我主要是在一趟长途航班上,花了很大功夫做了两套方案。

And I spent actually, I think it was mostly a long airplane ride and I basically did two designs for this.

Speaker 1

我先写了第一个冒出来的想法,然后对自己说:好吧,假如把这个方案全扔了,还能不能想出一个完全不一样的办法?

I did kind of the first idea that came to mind and then I said, Okay, suppose I'm gonna throw that out, what would be something that's really different that I could do?

Speaker 1

于是我就设计了第二个方案。

And did a second one.

Speaker 1

比较之后,我最终选了第二个想法,说实话,这真是我职业生涯里最棒的点子之一。

And after comparing them, I ended up choosing the second idea and honestly, that was one of the best ideas I've had in my professional career.

Speaker 1

Tk 工具包之所以受欢迎,就是因为它的接口简洁、优雅又强大,而这个接口正是我第二个方案。

One of the things that made TickleTK popular was that the API for TK was just a very sweet, simple, powerful API and it was my second choice.

Speaker 1

它是我脑子里冒出来的第二个主意。

It was the second thing that came to my mind.

Speaker 1

这个例子一直激励着我,每当我做新东西的时候,都会强迫自己至少想出两种不同的方案。

So I have that example, that always motivates me and when I'm doing new things I usually try and force myself to think of two ways.

Speaker 1

即使你觉得其中一个想法很糟糕,也试着想出一个你认为很差的替代方案,然后和你原来的方案对比一下,你一定能从中有所收获,说不定你会发现,那个你以为很糟的想法其实没那么差。

Even if I think one of them is really bad, even come up with what you think is a bad alternative and compare it to what you did, you'll learn something from that and you may discover the bad thing wasn't as bad as you thought it was.

Speaker 0

我最近才意识到,以前在优步工作的时候,我们有个叫设计文档、RFC 的流程,要求大家把做一件事的原因、怎么做之类的都写下来。

I'm actually starting to realize when I worked at Uber, we had this concept of design docs, RFCs, where you were expected to just, you know, like write down why you're doing something, how you're doing it, etcetera.

Speaker 0

过了一段时间,我们又加了一项内容,叫‘权衡’或者‘考虑过的其他方案’。

And after a while, we start to add a thing called trade offs or alter alternatives considered.

Speaker 0

我们要求每个人至少写出一个替代方案,最好是多个。

And we were asking people, like, write down at least one, ideally multiple alternatives considered.

Speaker 0

我们这么做是因为,结果发现设计、想法和计划都变好了,讨论也更深入了,因为大家能清楚地看到为什么某些方案被排除了。

And and we we did it because we it just like, we got better, you know, designs, ideas, plans, etcetera, and better discussions as well because it was clear why why you wouldn't do it.

Speaker 0

现在我回过头来想你刚才说的,其实我们当时就是在做一点点你提到的事——逼大家别只停留在第一个想法上,而是把其他可能的方案也写下来,再做比较。

And now I'm just reflecting on what you said on like, well, we were kind of doing a little bit of what you were saying, forcing people to not stop, either not get their first idea or put down others as well and compare them.

Speaker 0

你说,很多时候人们只是随便列一些明显行不通的点。

You said, oftentimes it will be people just doing, you know, okay, here's some things that will surely not work.

Speaker 0

而通常来说,确实也行不通,这也没错。

And usually fair enough, it doesn't work.

Speaker 0

但有时候他们会说,哦,其实这个挺简单的,我们直接用这个就行了。

But then sometimes they're like, oh, actually, that's a simple thing and we could just use that instead.

Speaker 1

或者我们可以把这两者结合起来。

Or maybe we combine these two things together.

Speaker 1

对。

Yeah.

Speaker 1

没错。

Yeah.

Speaker 1

你刚才问,这会不会花很多时间,拖慢进度?

And you you asked about does this take a lot of time and slow down the process?

Speaker 1

当然会多花一点时间,毕竟天下没有免费的午餐。

Well, it will take some extra time, of course, nothing is free.

Speaker 1

但说实话,这个层次的设计只是宏观层面的。

But honestly, the design at this level is a very high level design.

Speaker 1

我们并不是真要完整地再造一个替代方案。

This is not it's not like we're completely building a second alternative.

Speaker 1

我通常从宏观层面来思考这个问题。

It's I kind of think at the high level.

Speaker 1

关于TKL和TK这个设计,我可能花了几天时间,仔细考虑这两种方案并进行比较。

So with TKL and TK, this TK design, I might have spent maybe a few days on the design thinking about these two alternatives and comparing them.

Speaker 1

但真正实现TK花了整整一年,甚至更久。

But then it took a year to implement TK or more than that.

Speaker 1

所以,这在整个系统开发时间里,只占了大概1%到2%。

So we're talking something on the order of one or 2% of the total time to build a system.

Speaker 1

其实根本算不上什么大问题。

It's just it's not that big of a deal.

Speaker 1

只要它能带来更好的设计,你获得的回报远不止1%到2%。

And if it gives you a better design, you get back way more than one or 2%.

Speaker 0

是的。

Yeah.

Speaker 0

我觉得这是团队和工程师们都会慢慢领悟到的一课。

I feel this is a lesson that people, teams, engineers learn.

Speaker 0

我明白了。

I get it again.

Speaker 0

你知道吗,一开始总想着赶紧写代码,觉得那样更快。

You know, first, there's always a point where you jump into coding, I'm faster.

Speaker 0

但等到问题变复杂了,才意识到:哎,早知道该多花点时间好好规划一下。

And then when it's complex enough, you learn, oh, we probably should have planned a little bit better.

Speaker 0

那样的话,我能省下不少时间。

I would have saved myself time.

Speaker 0

过一阵子,又容易陷入过度规划,大家觉得计划太多,然后循环又重新开始。

And then after a while, the the the cycle goes into like too much planning or people feels too much planning and then it starts again.

Speaker 0

所以我觉得这就像个没完没了的循环——现在还有人老提瀑布模型,那都二十、三十年前的东西了。

So I I feel there's a little bit of never ending cycle, you know, there people still talk about waterfall, which which used to be a thing like twenty or or thirty years ago.

Speaker 0

其实早就不时兴了,但有些人还是看不惯快节奏的团队花太多时间做计划,觉得那是光说不练。

It's not really a thing, but peep like, there is some disdain, especially for fast moving teams in planning too much because it's seen as, you know, too much talking, not enough doing so.

Speaker 1

这个我也理解。

Well, and and I get that too.

Speaker 1

所以说,设计的核心就在于总是要做取舍。

So, you know, think the fundamental thing about design is it always involves trade offs.

Speaker 1

如果你把任何一个想法推得太远,最后很可能陷入困境。

And if you take any one idea and you push it too far you're probably going end in a bad place.

Speaker 1

至于多做几个设计方案这个想法,其实也一样,过度了反而适得其反。

So this idea about doing multiple designs, you could certainly take that too far also.

Speaker 1

真正厉害的设计师和普通设计师的区别,就在于他们懂得怎么权衡这些取舍,怎么把不同的想法和阶段融合起来,找到平衡。

And I think one of the things that separates the really good designers from the not as good ones is they kind of know how to make those trade offs and how to combine these different ideas and different phases and balance them off.

Speaker 1

这种能力大概只能靠经验慢慢积累。

And that's the kind of thing probably you just have to learn from experience.

Speaker 1

你亲自试过这两种方法,吃过它们的亏,时间久了自然就对其中的利弊有了直觉。

You know, you try both approaches and see the bad problems with them and then you eventually get a gut feel for what the trade offs are.

Speaker 0

书里有个观点让我印象很深,就是‘深模块’和‘浅模块’的概念。

Now in the book, one idea that stuck with me is this concept of deep modules and shallow modules.

Speaker 0

你提到,深模块指的是接口很简单,但内部功能非常丰富的一段代码或功能模块。

And you introduce this concept as a a deep module is something a piece of code or or functionality or well, a module that has a pretty simple interface, but it has a lot of depth to it.

Speaker 0

它的功能很丰富,结构也很复杂。

It has a lot of functionality complexity.

Speaker 0

而浅层模块呢,接口看起来很宽,但实际上没做什么实质性的工作。

And then a shallow module is something that has a wide interface, but it it doesn't do too much.

Speaker 0

有时候它甚至透明得让人觉得,它根本没怎么隐藏什么细节。

So it it kind of it almost it it might be even transparent in in some points that it it doesn't do much hiding.

Speaker 0

书里特别强调,深层模块对写出优秀的软件设计至关重要。

And in the book, emphasize how deep modules are important for good software design.

Speaker 0

为什么这么说呢?你是怎么得出这个认识的?

Why is this so and how did you again like come across this realization?

Speaker 1

归根结底,还是复杂性的问题。

Well, it all comes back to complexity.

Speaker 1

书里所有内容其实都源于一个问题:我们该怎么减少或应对复杂性。

And everything in the book really derives from this idea about how do we eliminate or manage complexity.

Speaker 1

而深层模块,正是我们对抗复杂性的有力工具。

And so a deep module is what gives us leverage against complexity.

Speaker 1

它通过提供一个非常简洁的接口来实现这一点。

And the way it does that is it provides this very simple interface.

Speaker 1

所以使用这个模块的人几乎没什么认知负担,学起来特别容易。

So people using the module have almost no cognitive load, very easy to learn.

Speaker 1

但模块内部却隐藏了大量功能和复杂性,外人完全看不到。

But inside the module there's a tremendous amount of functionality and complexity that is hidden from everybody else.

Speaker 1

所以‘深度’这个概念,我想表达的就是这种权衡。

And so that's in the deep notion, I was trying to capture the trade offs.

Speaker 1

本质上,这种权衡体现在两个方面:接口的复杂度和模块内部的功能多少。

And basically it's this trade off between two things, the complexity of the interface and how much functionality you have in the module.

Speaker 1

你要做的,就是用尽可能简单的接口,实现最多的功能。

And so what you want to do is get the most functionality you can for the simplest possible interface on top.

Speaker 0

在书里,你有一章叫‘把错误从存在中消除’。

In the book, you have a chapter titled Defining Errors Out of Existence.

Speaker 0

这一章里,你谈到了错误处理。

And in this one you talk about error handling.

Speaker 0

你对错误处理有什么看法?怎样才能设计出合理可靠的错误处理机制?

What is your take on error handling and how to design for, you know, sensible error handling?

Speaker 1

没错,这又回到了复杂性的问题上,任何写过不少代码的人都知道,错误处理是复杂性的一大来源。

Right, so again, this comes back to the complexity issue and anybody who's built a lot of software knows that error handling is a huge source of complexity.

Speaker 1

说白了,就是那些各种各样的特殊情况,你得一一应对的奇怪边界情况。

Basically it's, you know, it's all the special cases, all these weird special cases you have to deal with.

Speaker 1

所以错误处理很容易给软件带来巨大的复杂性。

And so it's easy for error handling to impose tremendous complexity on software.

Speaker 1

因此,我一直在问自己:怎么才能降低它的影响?

So then the question I'm constantly asking myself is how can we reduce the impact?

Speaker 1

我的意思是,确实有些情况我们不得不面对。

I mean, we do have some situations we have to deal with.

Speaker 1

有些异常是根本避不开的,你没办法绕过去。

There's some, you know, there's many exceptions you simply can't be avoided.

Speaker 1

它们是系统本身固有的部分,你只能去处理。

They're fundamental to the system so you have to deal with them.

展开剩余字幕(还有 480 条)
Speaker 1

还有一些情况,其实没那么重要。

Other cases where they're not so important.

Speaker 1

所以在那一章里,我想表达的是,异常越多并不一定越好。

So in that chapter what I was trying to argue is that exceptions having more exceptions is not better.

Speaker 1

有时候确实有必要。

It is sometimes necessary.

Speaker 1

但我总觉得,有些设计师以为,一个类抛出的异常越多,就越能体现自己是个优秀的程序员。

But I sometimes think that designers think that the more exceptions I throw from a class, the better a programmer I'm being.

Speaker 1

觉得自己更谨慎、更周到。

I'm being a more cautious, careful programmer.

Speaker 1

但我想说,不对,每个你抛出的异常,都会给使用你这个类的人增加负担。

And I would say, No, the problem is every exception you throw is imposing complexity on the users of your class.

Speaker 1

所以如果你能减少抛出的异常数量,减少那些特殊处理的情况,整个系统的复杂度就会降低。

And so if you can, if you can reduce the number of exceptions you throw, the number of special cases you generate, that will reduce system complexity.

Speaker 1

我在那一章里举了很多例子,说明只要对系统设计稍作调整,很多类型的错误根本就不会出现。

And I gave a bunch of examples in that chapter where in fact by just a slight change in the design of the system, whole classes of errors simply disappear.

Speaker 1

这种情况根本不会发生。

They can't happen.

Speaker 1

根本没什么需要处理的错误。

There is no error to deal with.

Speaker 1

不过我要提醒一下,这种事偶尔确实会出现,但你必须格外小心。

But I will say this is something that this happens occasionally, but you have to be very careful about this.

Speaker 1

在我教的软件设计课上,几乎每届学生都有人误解这一点。

And in the class I teach on software design, students have virtually every class there are people that misunderstand this.

Speaker 1

他们在第一个项目里,完全没做任何异常处理。

And in the first project they have essentially zero exception handling.

Speaker 1

他们正在构建一个分布式服务器,机器可能会崩溃,但他们连网络错误都不检查。

They're building a distributed server where machines can crash and they don't even check for errors in the network.

Speaker 1

我就问他们:你们这里连错误检查都没有,要是系统崩溃了怎么办?

And I say, you have no error checks here, what happens if a system crashes?

Speaker 1

他们回答:哦,我们直接把那些错误给排除掉了。

And they say, oh, we just defined those errors out of existence.

Speaker 1

我说,不对,错误依然存在,只是你没去管它。

I say, Well, no, the errors are still there, you're just ignoring them.

Speaker 1

你不能这么干。

You can't do that.

Speaker 1

所以,我觉得这一章我得特别提醒大家注意。

So anyhow, I think this is a chapter I have to warn people about.

Speaker 1

这个东西很容易被用偏了。

It's really easy to take this one in bad directions.

Speaker 1

就像香料一样,用一点点,炒菜能提味,但要是放多了,整个就毁了。

It's kind of like a spice, you know, they use tiny amounts of it and you're cooking and you get a good result, but if you use very much, you end up with a mess.

Speaker 0

是的,但我觉得错误、异常、系统出问题这些事,我们在设计时根本谈得太少了。

Yeah, but I feel errors, exceptions, things going wrong, they're they're one of the things that are we don't really talk to enough about it when we think about design.

Speaker 0

我回顾那些系统宕机事件时,记得很多都是在优步发生的,其他公司也一样。

When I look at outages, I I remember a lot of outages that we had specifically at at Uber, but even at other companies.

Speaker 0

很多时候我们查原因,发现都是因为错误处理不当。

A lot of the times when we looked into what caused it, it was, you know, like a mishandling of of an error.

Speaker 0

问题出在一个系统,我们误把它当成成功了。

It came from one system, we mapped it incorrectly as a success.

Speaker 0

还有很多类似的边缘情况,我们要么误解了错误,要么误解了意外的响应。

And there was a lot of these edge cases, which were we we misunderstood either errors or unexpected responses.

Speaker 0

说到底,其实都是同一类问题。

You know, they're all the same thing.

Speaker 0

说到底,还是跟错误有关。

It it was something with errors.

Speaker 0

我们当时就是说不清楚到底哪里出了问题。

And I think we struggled to put a finger on it.

Speaker 0

我们试过一些办法,比如改进响应的映射方式。

You know, we we we looked at ways that were like, okay, let's map map responses better.

Speaker 0

搞个白名单。

Let's have white list.

Speaker 0

搞个黑名单。

Let's have black list.

Speaker 0

但在规划阶段,我真不记得有这回事。

But during the planning phase, I don't really remember.

Speaker 0

我觉得规划的时候,大家总是很乐观,觉得系统会怎么运行,组件之间会怎么通信。

I feel for planning, people tend to be optimistic of here's how it works, here's how these things will communicate.

Speaker 0

我几乎不记得有哪次规划会讨论:‘万一出问题怎么办?’

And I rarely recall planning sessions where we thought, okay, what could go bad?

Speaker 0

我们怎么才能发现这些问题?

How will we catch it?

Speaker 0

我们怎么去恢复?

How will recover?

Speaker 1

你说得对,我同意你的看法——人们在做整体系统设计时,根本不会优先考虑异常处理。

So it's just I think you make a good point in that I think people don't I don't think exception handling is top of people's mind when they are doing the overall system design.

Speaker 1

通常都是等实际遇到问题了,才临时想办法解决。

It just kind of it just sort of happens tactically once people discover potential problems.

Speaker 0

没错,你正好说出了我想表达的这个观察。

Yes, this is I think you're putting what I'm trying to put as this observation.

Speaker 0

这真是个挺有意思的问题。

It's just a very interesting one.

Speaker 1

我给人们的建议是,当你在设计一个模块、考虑通过接口暴露哪些特殊情况和异常时,应该试着站在调用者的角度想一想:他们会怎么处理这些情况?在设计时,尽量代入用户的心态。

So the one general piece of advice I have for people is that when you're building a module and thinking about what kinds of special cases and exceptions you're going to export through your interface, You should think about how you think the callers are going to deal with these and try and put yourself in the mindset of the user as you're thinking through these.

Speaker 1

你看,与其搞出十种不同的异常,不如想想其实用户也就那么两三种处理方式,干脆把所有情况归成两类异常就够了,没必要搞十种。

See, rather than having 10 different exceptions, is it actually there's only really two different ways people are going to handle this and so I can boil it all down into two kinds of exceptions rather than 10 kinds of exceptions, for example.

Speaker 1

所以关键是要从调用者的角度来考虑问题。

So I think the key thing is to think about it from the caller's standpoint.

Speaker 1

说到这个,我想起一个优秀设计师最重要的特质之一,那就是

By the way, that brings me to I think what I think is one of the most important attributes of a really good designer, which is

Speaker 0

是什么?

What is it?

Speaker 1

他们能切换思维模式,从完全不同的视角来看待问题。

They can change their mindset and think about things from very different point of views.

Speaker 1

当我设计一个模块时,我会考虑这个模块的所有细节。

So when I'm designing a module, you know, I'm thinking about all of the details of that module.

Speaker 1

但这时候我可以切换视角,站在用户的角度来想,其实我不需要关心这些细节。

But then I can change my mindset to think about the user of this module and realize I don't want to have any awareness of those details.

Speaker 1

尤其是当我使用一个模块的时候,我绝不会去利用那些我知道的内部实现。

And in particular, you know, when I'm using a module, don't want to take advantage of things I might know about the inside of that module.

Speaker 1

我只该用接口里明确提供的那些功能。

I only wanted to use things in the interface.

Speaker 1

所以,能随时切换思维方式——一会儿深入细节,一会儿又彻底抛开它们,从完全不同的角度看问题,这真的特别重要。

And so being able to shift your mindset and think about things at one point, but then completely put those out of your mind and take a totally different view some other time, that's really powerful.

Speaker 1

好设计就是这样来的:设计的时候,也要想着将来谁会用它,他们会有怎样的体验。

That's how you come up with good designs, think, again, when you're designing something, can also think about it from the standpoint of somebody that's going to be using it.

Speaker 0

挺有意思的。

Interesting.

Speaker 0

所以你的意思是,具备同理心,能站在别人的角度思考——不管是用户、其他开发者,还是将来要维护这段代码的人——这能让我们成为更好的工程师?

So are you saying that having empathy and having the being able to put yourself in the shoes of another role, may that be a customer, another developer, another developer who will be working on this, that could make us a better software engineer?

Speaker 1

我正想说‘同理心’这个词。

I was about to say the word empathy.

Speaker 1

我本来想说的是,这种能力不仅在工程领域很有价值,在人际交往中也同样重要。

What I was going say is, I think this skill set has tremendous value in social context as well as in engineering context.

Speaker 1

能够站在别人的立场上去思考问题。

The ability to think about things from some other person's viewpoint.

Speaker 1

顺便说一句,我特别喜欢计算机科学的一点是,别人总觉得我们是书呆子,但其实我们用在系统里的很多理念,跟社会系统里的情况都有很有趣的对应关系。

By the way, one of the things I love about computer science, people think of us as sort of geeky, nerdy people, but many of the ideas that we use in computer systems actually have interesting analogies in social systems as well.

Speaker 0

确实挺有意思的,因为我刚开始走软件工程这条路的时候,跟你一样,学编程、上大学、找第一份工作,等等。

Yeah, it's just interesting because when I, you know, I'll start off like you on the software engineering journey, you know, start to learn to code, go to college, get my first job, etcetera.

Speaker 0

一开始我以为最难的是写代码,但后来跟每个有几年经验的开发者聊过之后,我们都达成一个共识:软件工程、编程里最难的,其实是人。

And initially I thought the hard part is the coding and every developer I talk to, every engineer I talk to above a certain years, we always have this discussion that the hardest part in software engineering, computers, and programming, it's the people.

Speaker 0

回想一下你工作头几年,等你掌握了语法、学会了调试,再回头看那些最让你头疼的项目,最大的问题往往不是技术,而是沟通不畅——比如需求理解错了,或者大家对事情的预期不一致。

You know, when we think back of after your first few years, once you get the syntax and and you learn how to debug and those things, you think about what was the hardest project that was, what was the biggest problem, what caused me the most headache, and it's oftentimes miscommunication, you know, like we misunderstood each other, the spec was off, etcetera.

Speaker 0

当然,系统崩溃也会发生,但通常根本原因是我们没料到这种情况会出现。

Of course, there's outages as well, but what usually the root cause is we did not expect this to happen.

Speaker 0

因为我们缺乏对用户的同理心。

We didn't have the empathy for the user.

Speaker 0

而且,最常见的是和同事之间的冲突,就是一起工作的人。

And and, yeah, it it usually and the biggest one is is conflicts with teammates, with people that you work with.

Speaker 0

全是人与人之间的问题。

It's all human things.

Speaker 0

这挺有意思的。

So it's interesting.

Speaker 0

有个笑话常说,计算机科学里最难的是缓存和命名,但我还得加上人这一项。

There's this joke that the hardest thing in computer science are, I think, caching and naming things, but I will add people as well.

Speaker 1

是的。

Yeah.

Speaker 1

这说法挺有意思。

That sounds interesting.

Speaker 1

没错。

Yep.

Speaker 0

你书里没提到的一点是,当然,书不可能涵盖所有内容,但很多团队和科技公司都会做一种叫设计评审和讨论的实践。

One thing that in your book you don't touch on, of course, know, the book cannot touch on anything, but it's a practice that a lot of teams and and tech companies use is these things called design reviews and discussions.

Speaker 0

意思是,在开始构建系统之前,有人会先把计划写下来。

The idea is that someone, before building a system, will write down a plan.

Speaker 0

然后大家可能会开个会。

People will either have a meeting.

Speaker 0

亚马逊就特别注重这种写作文化,大家聚在一间屋子里,先读计划,再一起讨论。

Amazon famously has this writing culture where people get get into a room, they they read the plan, and then they discuss.

Speaker 0

其他地方则常用谷歌文档,甚至像Figma这样的工具来完成。

In other places, it's done with Google Docs and and even some others like like Figma.

Speaker 0

他们会用自己熟悉的工具画图、做标注,互相反馈。

They use their own tools to kind of, like, draw visuals and comment on it.

Speaker 0

你觉得在动手之前,先通过白板或其他方式把计划讲清楚,再互相挑毛病,这做法怎么样?

What what is your take of before building a system explaining a plan, either whiteboarding or other ways, and then kind of criticizing each other's plans?

Speaker 0

你自己有没有在工作中用过类似的方法?

Have have you either done this to to some of the things that you do?

Speaker 0

你在教设计课的时候,会鼓励学生这么做吗?

Do you encourage students in your class, on design classes, to do this?

Speaker 1

当然了,我所有参与的项目都会这么做,以前做创业的时候,我们经常搞设计评审。

Oh yeah, we do this certainly all the projects I work on and certainly when I was doing startups, we would do design reviews.

Speaker 1

这些评审通常比较随意。

They were relatively informal.

Speaker 1

我们不会写很长的文档,但会聚在一起讨论想法。

We didn't have lengthy written documents, but we'd get together and talk about ideas.

Speaker 1

这时候,不同方案就会冒出来,大家讨论各自的利弊——只要能让多个人一起思考一个问题,出来的点子肯定比一个人单打独斗强得多。

And this is where again you get the multiple designs and you talk about the trade offs and you know, it's just if you can get multiple minds to think about a topic, it's pretty clear you're going come up with better ideas than if just one person does it.

Speaker 1

这其实也是个关键点,有些聪明人得先放下过去的习惯,因为他们以前待的环境里,根本指望不上别人给出有用的反馈。

Again, this is how, this is an area where smart people sometimes have to get past their history because they've been for much of their life in environments where they couldn't expect to get a lot of useful input from other people.

Speaker 1

但当你和一群顶尖聪明的人一起工作时,两个人的脑子肯定比一个人强,这是明摆着的。

But when you're working at the very highest level with very, very smart people, you know, two minds are better than one, clearly.

Speaker 1

所以我完全支持这种方式。

So I'm all for it.

Speaker 1

不过呢,也别陷入过度分析的陷阱里。

Again, you know, you don't want get caught in analysis paralysis.

Speaker 1

所以得琢磨清楚,到底该在什么时候做,花多少时间合适。

And so trying to figure out what's the right place to do it, how much time to spend on it.

Speaker 1

把握好这个度确实是一门艺术,但我完全支持这么做。

There's a certain art to getting just the right level, but I'm all for that.

Speaker 1

而且

And

Speaker 0

我觉得最近几年因为远程办公,情况可能变了。

I think this might have changed in the last few years because of remote work.

Speaker 0

你知道,远程办公曾经爆发式增长,现在又稍微收缩了一些。

You know, we've had an explosion of remote work and now it's a bit of a contraction.

Speaker 0

但2020年之前,那些最有创新力的公司,尤其是正在崛起的初创团队,办公室里到处都是白板。

But I remember before 2020, some of the most innovative companies, when you went into their thing or startups who were gaining momentum, what they had is whiteboards and and these erasable whiteboards everywhere.

Speaker 0

在那些地方,实际发生的情况是——我以前带过一个团队,我们甚至主动要求配白板——人正忙着自己的事,突然有人冒出个想法,你就说‘等等’,然后立马跑去白板前画起来,画完能擦掉,有时候就留着,有时候拍张照保存。

And what would happen in these places actually, I even had one of my older teams where we actually requested a whiteboard, is people, you know, you're just doing your thing, someone says something, you're like, hold on, and then you go to the whiteboard, you start whiteboarding and, you know, you can erase it, Sometimes you leave it there, sometimes you photograph it.

Speaker 0

说到底,就是随时触发、随需而动,任何一点灵感都能成为起点。

Basically, it it's just like on on demand when there's a it could be any trigger.

Speaker 0

也可能是听错了。

It could be just mishearing.

Speaker 0

有时候就是人聚在一起,把想法都摊出来,这种面对面交流有种特别的效果。虽然很多初创公司试图用数字工具来复制这种体验,但真正在现场把想法画出来,尤其是像软件这种东西,画框和箭头真的很有帮助。

It can be doing you just have people come together, do their ideas, and there's something special about there haven't startups have tried to replicate this digitally, but there's something special about in in person just, you know, like doing just getting your ideas out there, especially when we're talking about something like software where you do you know, boxes and arrows do help.

Speaker 1

我完全同意。

I totally agree.

Speaker 1

我特别喜欢白板,也喜欢面对面开会。

I love whiteboards and I like having meetings that are in person.

Speaker 1

在我的职业生涯中,我还发展出一种用白板解决复杂问题的方法,这些问题未必是技术性的。

I've also over my career developed a technique for using whiteboards to resolve complex issues, which may or may not even be technical.

Speaker 1

比如公司里其他类型的管理难题。

Other kinds of management issues in a company.

Speaker 1

我发现很多人开会时,总是各说各的,反复争论同样的观点,一圈一圈地打转,就是没法得出结论。

And what I found is that oftentimes people get in meetings and they just kind of talk past each other, repeat the same arguments and counter arguments and it just goes round and round and round and never reaches a conclusion.

Speaker 1

所以遇到这种情况,我会站在白板前,把支持和反对的理由都列出来。讨论的规则是:只要你觉得有道理,任何观点都可以提。

So what I do in these situations is I stand at the whiteboard and basically I list typically we're arguing for or against something, just list all the arguments for and all the arguments against and the rule of discussion is you can make any argument you think is reasonable.

Speaker 1

没人能说你的观点不成立,必须删掉。

No one is allowed to tell you your argument has to be removed, it's a bad argument.

Speaker 1

每个观点都要写到白板上。

Every argument goes on the board.

Speaker 1

但已经写上去的观点,不能再重复说。

But you are not allowed to repeat an argument that is already on the board.

Speaker 1

这一点特别关键。

And this is really important.

Speaker 1

把所有观点都公开摆在那儿,每个人的看法都算数,谁都能参与,没人能阻止你把自己的想法写上去。

So having the arguments up so everybody can see, everybody's argument is valid, you know, everyone's allowed to contribute, no one can stop you from putting your argument on the board.

Speaker 1

所以每个人的论点都会被列出来。

So everybody's arguments goes up.

Speaker 1

然后讨论会自然地走到一个没人再有新想法的节点。

And then the discussion just naturally reaches a point where nobody has anything more to say.

Speaker 1

这样一来,讨论时间就大大缩短了。

And so this shortens the discussion.

Speaker 1

接下来我会做个快速投票。

And then what I do after that is I take a straw poll.

Speaker 1

最让我惊讶的是,你真该试试看,因为这真的很惊人——人们在两边激烈争论,你以为他们完全对立。

And what's amazing to me, you should try this sometime because it's really, it's quite shocking, is that people will be arguing violently on both sides and you'll think there's total disagreement.

Speaker 1

但到最后,我们会做一次快速投票,告诉大家:你可以根据自己的判断,给这些观点赋予不同的权重。

And then at the end, and then we do a straw poll, you tell everybody, You get to weight these arguments in any way that you think is appropriate.

Speaker 1

你自己决定哪些观点更重要,哪些不那么重要。

You decide which ones you value, which ones you don't value.

Speaker 1

我们该选A还是B?

Should we do A or B?

Speaker 1

我们几乎总能达成非常强烈的共识。

We almost always end up with a really, really strong consensus.

Speaker 1

这真的让人意外。

It's shocking.

Speaker 1

我经常参加这样的会议,明明觉得大家意见完全不合,结果一投票,居然全票通过。

I'll be in these meetings where I think we have total disagreement here and then we do the vote and it's unanimous.

Speaker 0

嗯,看来我还没试过,所以这事儿听起来就像那种——我不是不信你,只是我自己没经历过,抱歉。

Well, it sounds I have not done it, so it's it's, you know, it sounds one of those things where I don't believe I wouldn't believe you, I'm sorry.

Speaker 0

但我真的相信你。

I I I do believe you.

Speaker 0

不过,就像你说的,我想我还是会去试试这个方法。

But, yeah, as as you said, I think, you know, I'm I'm gonna try to try this out.

Speaker 0

这事儿得靠白板。

It's a whiteboard.

Speaker 0

关键就在于

It's all about

Speaker 1

白板,我觉得。

the whiteboard, I think.

Speaker 0

没错。

Yeah.

Speaker 0

我觉得不管是听还是看的,都能明白为什么我这么喜欢这样的讨论。

And I think anyone listening or watching, just like this is why I love these discussions.

Speaker 0

这就像是拿到一个可以亲自试试的策略。

It's just like getting a tactic that you can try out.

Speaker 0

现在越来越多公司要求员工每周至少来几天办公室,你就可以拿块白板,直接试一试。

And now that more and more companies are doing at least a few days in the office, you get a whiteboard, try it out.

Speaker 1

顺便说一句,这种方法最适合那些人普遍聪明、理性,而且目标一致的环境。

By the way, this works best in environments where people are first generally pretty smart and reasonable and goal aligned.

Speaker 1

比如在初创公司或者工程团队里,大家通常目标一致,都想达成同样的结果。

Like, you know, in a startup for example, or an engineering team, you're typically goal aligned, you all want to achieve the same result.

Speaker 1

你说,这方法能在国会里用吗?两边政党意见对立的那种?

You know, would this work in Congress with opposing political parties?

Speaker 1

不行。

No.

Speaker 1

完全不行。

No.

Speaker 1

在政治环境中是行不通的。

Not in political environments.

Speaker 1

幸运的是,我们主要并不处在那样的环境中。

Fortunately, we don't operate mostly in those environments.

Speaker 0

确实如此。

Well, yeah.

Speaker 0

我觉得,从我的角度看,科技行业的发展趋势越来越明显了:即使在大公司里,大家也越来越认可团队需要有清晰的目标,因为如果没有目标,每个人都会往不同方向走。

And I think, you know, one nice thing about how the tech industry seems to be evolving from my perspective is it's more and more common and accepted, even at large companies, that you do want teams to have clear goals, like have those goals, because if you don't have it, everyone's gonna go in different directions.

Speaker 0

所以我觉得这种做法正变得越来越普遍。

So I think it's becoming more common.

Speaker 0

要是公司不这么做,很快就会陷入混乱。

Also, companies don't do it, they fizzle out pretty quickly.

Speaker 0

关于设计,也有个类似的问题。

So similar question on design.

Speaker 0

在设计这件事上,主要有两种看法。

There's two schools of of thoughts when it comes to design.

Speaker 0

一种是提前把设计做好,另一种是别提前设计。

One is let's design up front, and the other one is let's not let's not design up front.

Speaker 0

不如直接做原型吧,或者干脆先搭个东西出来,让代码自己说话。

Let's just do prototyping or just, you know, build something and let let the code decide.

Speaker 0

你更认同哪一种做法?

Do you subscribe to either of these approaches?

Speaker 0

是花时间提前规划,还是直接上手原型?你有没有遇到过某些项目,明显更适合其中一种方式?

Taking time upfront or just dropping into and prototyping, or have you seen times or types of projects where one just works better than the other?

Speaker 1

我个人觉得,设计贯穿在整个开发过程中。

My personal belief is that design permeates the entire development process.

Speaker 1

从一开始就要考虑设计,写代码的时候要,测试的时候要,修bug的时候也要,设计这个事得一直想着。

You do it upfront, you do it while you're coding, you do it while you're testing, you do it while you're fixing bugs, that you should constantly be thinking about design.

Speaker 1

我觉得至少得在开始前稍微规划一下。

I think you should always do at least a little bit of design upfront.

Speaker 1

当然,不是那种瀑布式的方法。

Again, you know, not waterfall method.

Speaker 1

我们必须意识到,现在的软件系统太复杂了,根本没法完全预判设计决策会带来什么后果。

It's important to realize that our software systems are so complicated that we are not able to predict the consequences of our design decisions.

Speaker 1

我们根本做不到。

We simply can't.

Speaker 1

但我认为提前做一些设计,带着一些假设去推进,真的很重要。

But I think it's really important to do some design and to have some hypotheses to work from.

Speaker 1

然后你开始实现,当然,一旦真正动手,所有计划都会被打乱,你会发现一大堆问题。

And then you start implementing and of course, you know, once you get in battle all your plans kind of fall apart and you'll discover lots of problems with it.

Speaker 1

所以一旦发现问题,你必须随时准备调整。

And so you have to be prepared to revise as soon as you discover problems.

Speaker 1

但如果你连一点前期设计都不做,我觉得你是在浪费时间写那些几乎不可能有用的代码。

But if you don't do any design upfront, I think you're wasting your time on code that is just very unlikely to be useful.

Speaker 1

我唯一会支持不设计就写代码的情况,是你太年轻、经验太少,根本不知道该怎么设计。

The only time I'd argue for coding without design is if you're so young and inexperienced that you really have no clue how to do design.

Speaker 1

那时候,你可能只能先写点代码,从实践中慢慢学。

Then, you know, you may just have to write some code and start learning from it.

Speaker 1

但无论如何,一旦发现问题,一定要做好重新设计的准备。

But in any case, absolutely be prepared to redesign, you know, as you discover problems.

Speaker 0

是的,很多年前我有个同事说过一句特别有意思的话,那时候我们已经都是有经验的工程师了,正在讨论为什么软件开发总是这么难。

Yeah, like I had one of my colleagues a long time ago, many years ago, he said something super interesting because we were talking about why software is and we were experienced engineers at this point.

Speaker 0

明明前期做了充分规划,为什么有些项目还是拖得特别久?

Like, why do some projects take a lot longer even if we do proper planning upfront?

Speaker 0

为什么有些项目反而挺顺利的?

Why are some projects actually, you know, they're they're pretty easy?

Speaker 0

他当时说了一番很耐人寻味的话。

And he says something interesting.

Speaker 0

他说,写软件就像在一片未知地形里行军,我们看得见目标,但脚下是什么完全不清楚。

He's like, software like, building software is a little bit like like we're in a terrain, you know, like and we need to march to that location.

Speaker 0

我们能看到终点,可路到底怎么走,谁也不知道。

We we we see that we see the target, but we the terrain is unknown.

Speaker 0

有时候一路走过去,一切都很顺,完全符合预期。

And sometimes you just walk there and it's exactly how you'd expect.

Speaker 0

但有时候正走着,突然一块大石头冒出来,你得爬过去,结果刚翻过去,又一块冒出来了。

Other times you're walking and, oh, suddenly there's a big kind of boulder appears out of nowhere, and you kind of climb over it, then another one comes.

Speaker 0

有时候你正走着,突然前面的地雷炸了,眼前出现一个大坑,你根本没想到这地方竟是雷区。

Sometimes you walk and, like, a mine explodes right in front of you, and suddenly you have this massive hole and you you didn't know this this was a minefield.

Speaker 0

他说了这话之后,我特别有共鸣,因为我觉得关键就在于有多少未知因素,以及应对方式完全不同。

And and he said and this analogy kind of resonated with me because I realized a lot of it is about, like, how how much unknowns are are unknowns, and the approach is just very different.

Speaker 0

对吧?

Right?

Speaker 0

比如你开发一个之前做过的技术栈或产品,跟完全全新的东西,或者用新技术、用框架的测试版,这些情况风险不一样,可能出问题,也可能顺利运行。

Like, if you're building a tech stack or product that you've done before versus something that is completely new, or using new technology, or using a beta version of a framework, it could have issues but maybe it'll work and so on.

Speaker 1

是的,我觉得很大一部分取决于你是否在熟悉的领域里工作。

Yeah, I think a lot of it has to do whether you're in a domain you've been in before or not.

Speaker 1

不是你运气好,碰上了一片平坦的地形。

It's not that you got lucky and there was a flat field.

Speaker 1

而是因为你以前走过这片山区,知道哪些路能走。

I think it's more that, oh, I've actually walked through this mountain range before and so I know the right paths.

Speaker 1

就像你之前做过五个设备的驱动,现在做新的,心里大概清楚会遇到哪些坑,流程也就更可预测、更顺畅了。

And so, you know, if you're a driver for a new device and you've built drivers for five devices before that, you kind of know what the main problems are and the process is much more predictable and smooth.

Speaker 1

如果你处在新环境里,说实话,也许我只是运气不好,但我从来没在新环境里有过顺顺利利的经历。

If you're in a new environment, well I don't know, maybe I'm just unlucky but I don't think I've ever had a smooth experience when I'm in a new environment.

Speaker 1

太难预测了。

It's just too hard to predict.

Speaker 0

我也是。

Neither have I.

Speaker 0

唯一算得上新环境的,其实也不算真新,比如框架的新版本,改动不大,或者语言的新版本,向后兼容所有重要功能,你也没用什么新特性,就是这类情况。

Like the only kind of new environment, well it's not really a new environment, like a new version of a framework and it's not a big change or you know, a new language release, which is backwards compatible with all the important stuff, but you're not using a new features, that kind of stuff.

Speaker 0

但这种算假的新吧?

But it's kind of fake, right?

Speaker 0

其实跟以前差不多。

Like you're, it's kind of the same as before.

Speaker 0

我想聊聊写这本书的事。

One thing I'd like to get into is the writing of this book.

Speaker 0

因为这本书给我的感觉是,里面全是特别实用的见解。

Because again, like this book, it feels to me, it has just a lot of really kind of practical insights.

Speaker 0

首先,我没怎么见过专门讲软件设计的书。

Now, first of all, haven't seen many books written about software design specifically.

Speaker 0

你是怎么想到要写这样一本书的?说实话,这事儿挺难理清的。

Did you get the idea to even start writing a book about this, you know, like a It's pretty hard to tangle

Speaker 1

这其实是个挺漫长的过程,但它的起点是我当年在斯坦福教的那门课。

kind of a long process, but the path leads through the course I taught at Stanford.

Speaker 1

所以背景是这样的,就像我之前说的,我特别喜欢写代码。

So the background for this is, as I mentioned earlier, I love coding.

Speaker 1

我是少数还坚持写大量代码的教授之一。

I'm one of the few professors that still writes large amounts of code.

Speaker 1

我每年至少要写个五六万行,甚至十万行代码。

You know, I try to write five or 10,000 lines of code a year, at least.

Speaker 1

写代码占了我相当大一部分时间。

It's been a significant fraction of my time coding.

Speaker 1

而且我特别喜欢设计。

And I love design.

Speaker 1

我觉得,设计是人类历史上最了不起、最有创造力的形式之一。

I think design is one of the most amazing, creative forms that has ever existed in the history of humankind.

Speaker 1

这真是个既迷人、优美,又充满挑战的领域。

It's just really fascinating, beautiful, challenging domain.

Speaker 1

所以我经常琢磨,到底什么才算好的设计?怎样才能写出优秀的软件?又该用哪些方法呢?

And so I've often I think about it and I try to think, what is a good design and how do I get to how do I design software that's good and what are the techniques for that?

Speaker 1

但渐渐地,我惊讶地发现,根本没人教这个。

But over time I noticed, to my shock, nobody teaches it.

Speaker 1

说实话,除了我后来在斯坦福开设的这门课,我敢说全世界再找不到第二门课,把软件设计本身——而不是工具或流程——作为核心内容来教。

Literally, other than the course I eventually started at Stanford, I don't think there's a single course anywhere in the world where software design, not tools or processes, but the act of software design is the primary element of the course.

Speaker 1

这件事在我心里压了十多年,越来越重。

And so this just kind of graded on me for, I don't know, a decade or more.

Speaker 1

等我回到斯坦福的学术圈,加上之前在业界积累的大量开发经验和想法,我才真正开始认真思考这个问题,最后决定:管它结果如何,先开一门课试试看。

And once I got back to academia at Stanford and now I have this experience in industries where I'd have a lot more software development experience and more ideas myself, I started thinking about this and I finally decided I'm just going who knows what's gonna happen, but I'm just gonna try teaching a course, see what I can do.

Speaker 1

这逼着我梳理自己的想法,试着把它们提炼成一些简单明了的原则。

And so that forced me to start thinking about my ideas and try and capture them in sort of simple principles.

Speaker 0

你说没人教设计。

You said no one teaches design.

Speaker 0

我跟你讲讲在科技公司工作的人怎么看这个问题。

You know, I'll tell you the perspective from like someone working at a tech company.

Speaker 0

通常我们招聘应届生或者工作几年的新人,都不会考软件架构这类问题。

Like, usually we don't interview new grads or people with a few years experience on this on software architecture topics.

Speaker 0

面试一般就两块:写代码,然后设计一个复杂系统。

Usually there's interviews coding and then software architecture or design a complex system.

Speaker 0

原因很简单,你得在行业里干上几年,才能慢慢体会到这些东西。

And the reason being, well, you need to work in the industry for several years to start to get a sense for for for this thing.

Speaker 0

但我感觉你其实是把这整个逻辑给翻过来了。

But I have a feeling you kind of you know, you turned this upside down.

Speaker 0

你通过这门课,其实是在证明——哪怕刚学会编程的学生,也能学会设计。

You're you're you've kind of proven or well, you're attempting to to to do with the class that design can be taught even for students who have recently learned to code.

Speaker 0

你的方法是什么?那些上过课的人反应怎么样?尤其是现在,有些人已经工作好几年了,他们回来的时候,带着一套同龄人没有的本事。

What what was your approach and and what what has your response been from from the people who've done it, especially now that, you know, some of those folks are have been out of industry for years, and I'm sure they're coming back with some of their experience because they now have a skill set that a lot of their peers do not.

Speaker 1

是的,所以我决定开这门课,接下来的问题就是:我该怎么教呢?

Yeah, so I decided to teach this class and then the question is, well, how do I teach it?

Speaker 1

我用的模式,是我高中时的英语写作课。

And the model I used was my English writing classes from high school.

Speaker 1

我不确定现在是不是还这样教,但当年我学英语写作时,老师布置作业,你写完交上去,老师批改后,你再修改重交。

I don't know if this is the way it's still done today, but back when I took English, the way you learn to write is you would get an assignment, you'd write something, your teacher would mark it up and then you would rewrite it and submit it again.

Speaker 1

有时候得反复改好几遍。

And you might do several iterations on it.

Speaker 1

我觉得关键有两个:第一,得到反馈。

And I think the key elements are first, getting feedback.

Speaker 1

得有人能对你的作品提出批评意见。

So you have somebody that can criticize your work.

Speaker 1

第二,根据反馈重新做一遍。

And then second, redoing to incorporate that feedback.

Speaker 1

真正把反馈和概念内化,其实是在反复修改的过程中发生的。

And it's the process of redoing something, I think, where you really internalize the feedback and the concepts.

Speaker 1

所以这门课就是这样教的。

So that's the way the class is taught.

Speaker 1

整个学期下来,学生们会分三个阶段完成一个比较重要的项目,然后我们会进行深入的代码评审。

It's over a course of a quarter, people do basically three stages where they build something significant and then we do extensive code reviews.

Speaker 1

比如说,我每一份团队的代码都会逐行审阅,这意味着

For example, I read every line of code for all the teams in the class, which means

Speaker 0

那学生们到底都做些什么呢?

And only what do people build?

Speaker 0

这个项目具体是做什么的?

What is the project?

Speaker 0

能举一个具体的项目例子吗?

Or what was one of the projects?

Speaker 1

实际上,前两个项目正好是把 Raft 一致性协议拆成了两个阶段来实现。

So actually the first two projects happened to be the raft consensus protocol divided up into two phases.

Speaker 1

这个设计其实有不少巧妙的难点,特别容易让学生犯错。

And that's actually turns out to have some really interesting design problems that confound students and lead to lots of mistakes.

Speaker 1

整个过程是这样的,一开始我什么都不提示,不给任何线索,也不提供结构。

So it's this process of, and when they start off I give them no clues, no hints, no structure.

Speaker 1

他们必须从零开始完全自己搞定。

They have to do it completely from scratch.

Speaker 1

这可是他们人生中第一次做这种事。

This is the first time in their lives they've ever done anything like that.

Speaker 1

所以对学生来说,这既特别有趣,又特别让人紧张。

So it's actually both very fun and very scary for the students.

Speaker 1

接着我们会进行深入的代码评审:课堂上大家互相看项目、提意见,而我会逐行阅读每一份代码,每支团队我都会花大约一小时跟他们讨论。

And then we do this extensive code review where they review it in class and other students read their projects and give feedback and then I read every line of code and I spend about an hour with each team.

Speaker 1

他们写的代码通常有两三千行,我会给出五到一百条反馈。

They typically get 50 to 100 comments from me on their, so two to 3,000 lines of code they've written.

Speaker 1

然后他们再回去修改。

And then they go back and they rework.

Speaker 1

我觉得真正的成长时刻,就发生在这些时候。

And I think that's when the moments come from students.

Speaker 1

当他们收到我的反馈,我指出代码太复杂的时候。

When they get the feedback from me where I can point out code is complicated.

Speaker 1

大家通常都知道代码复杂,但我会具体说明为什么复杂——因为你没遵循我们之前讲过的那个原则,而如果你照着做,代码就能简单多了。

People generally know that code is complicated but then I can point out, here's why it's complicated because you didn't follow this principle that we've been talking about and here's how if you apply the principle, you can make it simpler.

Speaker 1

等到他们交第二个项目时,质量明显提升了很多。

And then they come back with their second projects and the second projects are so much better.

Speaker 1

你能感觉到学生特别兴奋,因为他们真正体会到了自己的能力。

And you can tell the students are really excited because they can kind of feel their power.

Speaker 1

他们意识到,原来我能让这个东西变得好这么多。

They can feel that I was able to make this a lot better.

Speaker 1

所以我一开始还担心学生会对这门课有什么反应,结果他们的体验非常好。

And so, you know, I was worried about how the students would react to the class, so it's an extremely positive experience for the students.

Speaker 1

整个学期下来,你能明显看到他们对软件的理解发生了深刻的变化。

You can tell over the course of the quarter the way they think about software has changed really in significant ways.

Speaker 1

学期快结束时,我还特意提醒他们:你们以后进公司会发现,很多连资深工程师都不懂的东西。

And actually I warned them at the end the quarter, I say, you know, I just want to warn you, when you go into companies, you're going to find you know a lot of stuff that people in the companies don't know, even much more senior engineers.

Speaker 1

所以我们讨论如何应对这种情况,因为作为新人,你可能没什么能力去改变公司。

So then we talk about how do you deal with that because as a junior employee you may not have much ability to change the company.

Speaker 1

但我完全相信,设计是可以通过教学传授的。

But anyhow, so I totally, totally believe design can be taught.

Speaker 1

当然,经验还是必不可少的。

Now you still need experience.

Speaker 1

不是说上完我这门课,你就能立刻成为世界级程序员。

Know, it's not like you're going be a world class programmer after one quarter in my course.

Speaker 0

是的。

Oh yeah.

Speaker 1

但我认为,至少他们可以启动这个过程,获得一种全新的软件思维方式,这跟他们以前在课堂上学到的都不一样。

But I think that's they can start the process in motion and give you a new way of thinking about software that you've never thought about in your classes up till now.

Speaker 0

对。

Yeah.

Speaker 0

我觉得,经历过这门课的学生,他们的经验会慢慢积累起来。

And I think you can probably like my sense is that the students who go through this class and and, you know, they they build up their experience.

Speaker 0

他们也在这个过程中更了解自己。

They also learn about themselves.

Speaker 0

他们学会如何挑战自己,以及如何表达这些想法。

They they learn how they can challenge themselves, how they can talk about it.

Speaker 0

其他软件开发者通常进入行业后的头几年,都是靠碰壁慢慢积累经验的。

Other software developers take, you know, like, when you enter the industry, like in the first few years, you're just gonna like learn the hard way.

Speaker 0

我记得我刚毕业、还是初级开发者的时候,那时候我其实还在上学,但已经在公司上班了,一位资深开发者告诉我:你得这么做。

Like, remember that when I was a new grad or a junior developer, you know, started out of college, right, I was actually still doing college, but I was working at a workplace And a senior developer told me, I need to do this.

Speaker 0

他让我做规划,说我们要用这项技术,你得实现这个功能和那个功能。

You know, did the planning, we're gonna use this technology, you need to implement this and this.

Speaker 0

我当时心里总觉得不对劲,但还是照做了。

And I just had a bad feeling about it, but I did it.

Speaker 0

结果问题越积越多,越来越复杂。

And it it it just became worse and worse and more and more complicated.

Speaker 0

那个解决方案用的是公司自研的数据库,本来就性能不好,情况变得更糟了。

And if the the solution that it was some some in house database that had performance issues, it got bad.

Speaker 0

情况变得特别糟,后来那些资深开发人员都躲开了。

It it got really bad, and, you know, the developers the senior developers stepped away.

Speaker 0

结果项目搞了几周后,客户特别不满,因为页面加载要十五秒,这完全说不过去。

And in the end, like, weeks into the project, the the customer is frustrated because, like, a page load took fifteen seconds, which is on a like, it's it's not it was not okay.

Speaker 0

然后我就在周末一口气干了二十多个小时,没怎么休息。

And then I I just, over a weekend, I I I worked I must have worked for, like, I don't know, twenty plus hour.

Speaker 0

我干脆重写了整个系统,按我自己的方式来,所有问题一下子就解决了。

I just rewrote the whole thing the way I I would have done it, and it all of the things were fixed, etcetera.

Speaker 0

但那时候我心里总在想,我是不是有点太固执了?

But it it felt to me like I I was kind of like I was thinking like, am am I being crazy?

Speaker 0

毕竟那位有经验的人明明告诉我该这么做。

Like like, this experienced person told me to do this.

Speaker 0

我当时根本说不清哪里不对。

I just didn't really have the vocabulary.

Speaker 0

我也不够相信自己,没底气觉得我能做得更好。

I didn't have the the faith in in myself as well that that I I can do this.

Speaker 0

每个人迟早都会经历这些。

So and everyone goes through these things eventually.

Speaker 0

对吧?

Right?

Speaker 0

你慢慢就会明白,得自己碰过壁才知道,但我感觉你可能在给这些学生省去一些弯路。

Like, you kinda learn, you you burn yourself, but I I feel you might be giving those students a bit of a shortcut to to maybe avoid some of these pitfalls.

Speaker 1

我觉得那段经历对你来说特别有帮助。

I suspect that experience was really good for you.

Speaker 0

确实很有帮助,完全没错。

Oh, it was really good, totally.

Speaker 1

先走错一遍,让你的直觉得到验证。

Do it the wrong way and see your gut feeling validated.

Speaker 1

下次你就能说得更清楚,为什么那样做有问题,再回头用正确的方法做一遍,就能体会到差距有多大。

So next time around you can probably kind of put some words to that and talk more with more authority about why that's a problem and then going back and doing it the right way and seeing how much better it is.

Speaker 1

那对你来说一定是一段特别宝贵的经历。

Mean that must have been a really great experience for you.

Speaker 0

我觉得最棒的是,这些经历都是特别好的学习机会。

Like the the cool thing is that I think all of these things are like really good learnings.

Speaker 0

我本来想说的是,

I wouldn't have Shout out

Speaker 1

或许能帮其他人少受点罪。

any to other suffering maybe.

Speaker 1

对,不过我

Yeah, but I

Speaker 0

我觉得有时候这才是最让人印象深刻的学习经历。

feel that's sometimes that's the most memorable learning.

Speaker 1

我认为几乎所有学习都来自于犯错。

I think almost all learning is about making mistakes.

Speaker 1

学习最有效的方式就是犯错,然后去观察、理解为什么会错,最后加以改正。

That the way you learn, the most powerful ways to learn are to make mistakes, see, understand why they're mistakes and then fix them.

Speaker 1

对我来说,教育本质上就是创造一个安全的环境,让人们能够犯错并从中学到东西。

And to me, education is about basically creating a safe space where people can make mistakes and learn from them.

Speaker 1

我会在课堂上跟学生们讲这件事。

And I tell the students in the class about this.

Speaker 1

我会告诉他们:你们会收到大量的批评。

I tell them, you know, you're going to get a tremendous amount of criticism.

Speaker 1

我会逐行挑你们代码里的毛病。

I tell them, I am going to pick every single knit with your code.

Speaker 1

你们可能会因为我挑的这些问题生气,但我就是要让你们看到每一个错误,因为我想让你们意识到这些问题的存在。

Going to think there, you're going probably be mad at me for things I'm picking, but I'm going to show you every single thing that's wrong because I want you to be aware of that.

Speaker 1

我希望学生们从这门课中学到的一点是,这种经历其实非常有帮助。

One of the things I hope students get out of the class is realizing that's a really productive experience.

Speaker 1

有人来挑我的毛病、仔细审查我的代码、给我反馈,这对我来说其实是好事。

It's actually good for me to have people come in and challenge me, scrutinize my code and give me feedback.

Speaker 1

我觉得很多开发者其实挺敏感的。

Because I think a lot of developers out there are kind of sensitive.

Speaker 1

他们可能担心,别人批评自己的代码,就等于说他们不是个好程序员。

Maybe they worry that if somebody criticizes their code, maybe that means they weren't such a good coder.

Speaker 1

或者他们觉得,如果得想第二个方案,那就说明自己不够聪明。

Or maybe they think if I have to come up with a second idea, maybe I'm not that smart.

Speaker 1

只有笨人才会把同一件事做两遍。

Only dumb people have to do things twice.

Speaker 1

聪明人第一次就能把事情做对。

Smart people always get things right the first time.

Speaker 1

于是你就死死抓住一个想法:我绝不能承认自己的第一个想法不够好。

And so then you latch onto this, I can't ever admit that my first idea isn't great.

Speaker 1

所以我觉得,承认犯错这个观念特别重要,也特别有建设性。

So I think it's really important, whole idea of making mistakes is so important and so constructive.

Speaker 1

作为工程师,我们真该尊重这一点。

We need to honor that, I think, as engineers.

Speaker 0

话题稍微换个方向,你和鲍勃叔叔——罗伯特·马丁——曾经在网上就他的《代码整洁之道》有过一场有趣的讨论,你们俩分别对书里的不同部分写了看法。

Slightly different topic, but you and Uncle Bob, Robert Martin, had an interesting discussion about his book, Clean Code Online, where you both like wrote your thoughts on different parts.

Speaker 0

其中有几处,你们的观点不太一样。

And there were a few parts where your opinions diverged.

Speaker 0

我其实挺想深入聊聊这些观点的。

And I I was interested in in getting into some of these.

Speaker 0

第一个是关于短方法,也就是每个方法只做一件事。

So first was on short methods and the methods doing just one thing.

Speaker 0

罗伯特·马丁特别推崇这种做法。

You know, Robert Martin is is a big fan of of doing so.

Speaker 0

他说这样能让代码更干净,职责更清晰,等等。

He's saying this will lead to cleaner code, clear responsibility, and so on.

Speaker 0

但你的看法稍微有点不一样。

And you had a slightly different take on this.

Speaker 1

没错,我确实这么认为。

Oh, sure do.

Speaker 1

我之前提到过,设计本质上是权衡取舍。

So I mentioned earlier on that design is about trade offs.

Speaker 1

任何理念一旦走极端,最后都会陷入困境。

And if you take any idea and take it to the extreme, you end up in a bad place.

Speaker 1

所以我觉得,整洁代码在很多地方确实带来了这样的影响。

And so I think clean code has done that in many places.

Speaker 1

而这正是我最担心的整体问题。

And this was my biggest overall concern.

Speaker 1

因此,方法的长度就是其中一个方面。

And so method size is one of them.

Speaker 1

当然,我们都同意,特别长的方法通常比短方法更难理解和维护。

So of course I think we agree that really long methods are probably harder to understand and deal with than shorter methods.

Speaker 1

所以短小确实有它的价值。

So there's some value in shortness.

Speaker 1

但对我来说,最重要的不是方法有多短,而是它的抽象深度。

But it isn't the method length per se that's most important to me, it's this notion of depth.

Speaker 1

我们有没有把复杂性隐藏起来?

Are we hiding complexity?

Speaker 1

而在整洁代码的理念里,短小被当成了一种绝对的好,没有任何界限。

And so what happened in clean code is that shortness was taken as an absolute good with no limits on it.

Speaker 1

越短越好。

The more you get shorter, the better.

Speaker 1

按照《清洁代码》的说法,三行的函数比五行的更好。

And so a three line method is better than a five line method according to clean code.

Speaker 1

但问题在于,虽然单个函数可能更容易理解,但函数太短会导致数量暴增,接口也跟着变多。

And the problem with that is that, well, maybe that one method is a little bit easier to understand but by having shorter methods you now have a lot more methods and so you have a lot more interfaces.

Speaker 1

结果,接口的复杂性反而让整个系统比以前更难搞了。

And now the complexity of the interfaces ends up actually making the system more complicated than it was before.

Speaker 1

特别是他的风格,他觉得函数之间互相交叉也没关系。

And in particular, his style, he is comfortable if methods are entangled.

Speaker 1

一堆短函数,结果你得同时看好几个才能搞懂其中一个。

Having multiple short methods where in fact they're so entangled that you can't understand one method without actually looking at the code of the other methods at the same time.

Speaker 0

是啊,那干脆就这样吧。

Yeah, so might as well, yeah.

Speaker 1

在我看来,这种做法根本没什么好处。

To me I see no benefit of that.

Speaker 1

我觉得这样反而让事情变得更糟了,而不是更好。

I think to me that has made things worse, not better.

Speaker 1

如果某些东西确实密切相关,不如把它们合并在一起。

That if things are really related, you're better off pulling them together.

Speaker 1

别光盯着‘深度’这个概念,它其实能帮你权衡利弊。

So don't think about the notion of depth as it kind of captures the trade offs.

Speaker 1

我们希望功能丰富,但接口必须尽量简单。

That we want to have a lot of functionality but it needs to have a relatively simple interface.

Speaker 1

我觉得这个理念能帮你避免走向任何一个极端。

And so I think that notion will keep you from going astray in either one direction or the other.

Speaker 1

而像单一职责原则、只做一件事这些说法,只会一味地推着你往一个方向走,毫无节制,最后反而出问题。

Whereas this, for example, the single responsibility principle, the do one thing principle, that just pushes you relentlessly in one direction without any bounds and you get in trouble that way.

Speaker 0

你刚才提到方法要短、只做一件事,可以有很多小方法,也可以把它们合并成更大的方法,虽然做的事更多,但更合理。

And it's interesting how, you know, you talked about methods being short doing one thing and you can have a lot of them or you can like group them and have bigger methods that do do more thing, but they're more sensible.

Speaker 0

听你这么说,我想起我们行业里微服务也遇到过类似的情况。

I was thinking as you're talking about this, in the industry, we've had a similar thing with microservices.

Speaker 0

那时候我正好在Uber工作,公司当时流行说有五千多个微服务,我们确实有很多特别小的微服务。

So I happened to work at Uber at the time where it was popularized that the company had more than 5,000 microservices, and we had a lot of really small microservices.

Speaker 0

这些年下来,至少在我所在的领域——支付系统——我们之所以用这么多小服务,是因为它们启动起来方便。

And what happened over the years is, at least in my I cannot speak for the whole company, but I can talk about the domain I was, which was in the payments domain, we had a lot of small services because they were easy to spin up.

Speaker 0

每个服务就做一两件事,或者少数几件事。

They did like one thing or two things or a few things.

Speaker 0

但过了一阵子我们发现,维护起来太难了,根本搞不清哪个服务负责什么,来回调用特别多。

And after a while, realized like, it's it's just really tough to maintain, to know which lives there, a lot of communication back and forth.

Speaker 0

所以我们开始把它们合并起来,搞一些中等规模的服务,每个服务对应一个明确的业务领域。

So we started to just pull them together and create like mids I would say, like mid sized services that kind of had a domain responsibility.

Speaker 0

我们没走极端,但说实话,一开始那种极端做法听起来确实很吸引人。

And it wasn't either extreme, but, like, I think we saw that one extreme it sounds good.

Speaker 0

刚听说的时候,感觉特别棒,确实有不少好处。

It it sounded really good, by the way, initially, and it has benefits.

Speaker 0

但时间一长,发现实际操作起来并不靠谱。

But over time, it just wasn't as practical.

Speaker 0

所以这跟你所说的有点相似。

So it's somewhat similar to to to what to what you say.

Speaker 0

极端的做法,不管哪一边,都不太好。

Like, extremes on one end are not great.

Speaker 0

搞一个什么都能做的巨型服务,其实并不理想。

It's not great to have, like, one massive service that does everything.

Speaker 0

以前Uber就是这样。

You know, we Uber used to have that.

Speaker 0

那个服务叫API,啥活都干。

It was called API, and it did everything.

Speaker 0

后来拆成了很多小服务,再后来又慢慢收拢,归到一些明确的领域里,规模也适中了。

And then it got broken into smaller things, and then it came back into, like, kind of domains or or reasonably sized ones.

Speaker 0

这样你心里才清楚每个部分是干嘛的。

So so you could actually keep track in your head.

Speaker 0

你能明白系统里到底有哪些模块在运行。

You could understand here are the different parts that are there.

Speaker 0

明白了。

Okay.

Speaker 0

你可以深入进去,看看各个部分是怎么运作的。

You can go inside and then you can understand the parts.

Speaker 0

所以我觉得关键在于,什么时候才算是恰到好处?

So there's I think there's a level of when does it make sense?

Speaker 0

你怎么判断这些划分是否合理呢?

How can you follow those kind of things as well?

Speaker 1

我觉得两边都有道理,但如今很多人倾向于过度拆分。

I think there's a you know, again you can on both sides, but I think these days people often on the side of over decomposing.

Speaker 1

比如《代码整洁之道》就提倡一种我认为过于拆分的做法,反而会带来问题。

And I think so Clean Code, for example, advocates that, what I consider to be over decomposing that causes problems.

Speaker 1

所以我常告诉学生,有时候把东西合并起来,反而能让设计更深刻。

And so one of the things I tell my students is often you can make something deeper by actually combining things together.

Speaker 1

如果两个东西本来就很相关,把它们合并成一个类、一个方法、一个模块或者一个子系统,不仅能保留全部功能,还能让整体接口更简洁,避免两个独立组件之间产生大量耦合——那可是大忌。

If they were closely related, you may discover that if you bring them together into one class or one method or one module or one sub system, you end up with the combined functionality but with a simpler overall API and without having two separate things with a lot of dependencies between them, which is really bad.

Speaker 1

不过这种做法也容易走极端,毕竟凡事都有权衡,有时候把单元做得大一点,反而能让代码更好。

Again, you can overdo this, you know, so everything is trade offs, but you can often make things better by making the units a little bit larger.

Speaker 0

屏幕上另一个话题是测试驱动开发,我们之前稍微提过。

Another area of this screen was test driven development that we touched on a little bit.

Speaker 0

罗伯特·马丁特别推崇测试驱动开发,主张先写测试,再写能通过测试的代码。

Robert Martin is a big fan of using TDD as a way to write code, write the test first, then write the code that makes it pass.

Speaker 0

这种方法在2000年代初还挺流行的。

This method was also pretty popular in the early 2000s.

Speaker 0

不过现在没那么时兴了。

It's kind of gotten a little bit out of style.

Speaker 0

你的看法也不太一样。

Your take was different as well.

Speaker 1

是的,我不太认同测试驱动开发。

Yeah, I'm not a fan of TDD.

Speaker 1

没错。

Yep.

Speaker 1

因为我觉得它会妨碍设计。

Because I think it works against design.

Speaker 1

所以再说一遍,对我来说,软件测试很重要。

So again, to me, software, so tests are important.

Speaker 1

我特别喜欢单元测试。

I love unit tests.

Speaker 1

我写的每一段代码都会配上测试。

I've read them for everything I do.

Speaker 1

它们是必不可少的。

They're essential.

Speaker 1

一个负责任的开发者,都会写出高覆盖率的单元测试。

If responsible you're developer, you write unit tests with very high coverage.

Speaker 1

这一点我们先达成共识。

So let's agree on that.

Speaker 1

但我们的开发过程应该更聚焦在设计上。

But we want the development process to be focused on design.

Speaker 1

我觉得,我们所有开发工作都应该围绕着做出最佳设计来展开。

I think that should be the center of everything we do in development should be organized towards getting the best possible design.

Speaker 1

我认为TDD恰恰与此背道而驰,因为它让你只关注一个个微小的设计片段。

And I think TDD works against that because it encourages you to do a little tiny increment of design.

Speaker 1

我写一个测试,然后写代码让这个测试通过。

I write one test and then I implement the functionality to make that test pass.

Speaker 1

接着再写一个测试,再写代码让它通过。

Then I write one more test and write the functionality to make that test pass.

Speaker 1

整个过程中,根本没人鼓励你停下来,从整体上思考任务和大局。

And so there's no point in the process where you're encouraged to step back and think about the overall task, the big picture.

Speaker 1

这些部分该怎么协同工作?

How do all these pieces fit together?

Speaker 1

什么样的架构才最简洁、优雅,能一次性解决十个问题,而不是为每个问题单独拼凑十个方案?

What's the most pleasing, simple, clean architecture that will handle, that will solve 10 problems rather than coming up with 10 solutions to individual problems.

Speaker 1

所以,我认为这样做的风险是,最终会陷入一种极度短视的开发模式,产出的东西一团糟。

And so it results in what I believe the risk is you can end in an extremely tactical style of development that produces just a horribleness.

Speaker 1

这就是我的担忧。

So that's my concern.

Speaker 1

我们之前为此争论了很久,我觉得Bob喜欢TDD的主要原因,是他觉得这样能确保测试代码被写出来——因为你必须先写测试,再写功能代码。

And we had this long back and forth about it and I think the main reason that Bob likes TDD is it ensures that the tests get written, because you have to write the test before the code.

Speaker 1

所以,

So I

Speaker 0

我同意,这一点确实说得通。

agree Which that that is should fair.

Speaker 1

但我并不觉得,除了确保测试被写出来之外,先写测试再写代码还有什么特别的优势。

But I don't think there's anything he was not able to convince me that there's any particular advantage in writing the test before the code other than ensuring that the tests get written.

Speaker 1

我看不出它能让设计变得更好,反而能想到很多理由说明它可能会让设计变得更糟。

It does not I can't see any reason that makes the design better and I can see a lot of reasons why it might make the design a lot worse.

Speaker 1

我觉得一个有趣的问题是:我们开发时,应该以什么为单位来划分工作?

I think an interesting question is what should be your units of development?

Speaker 1

你知道,开发总是要分块进行的,那这些块应该怎么划分才合理?

You know, you're going to do development is always in chunks of work, what should those chunks be?

Speaker 1

我认为这些开发单元应该是抽象层面,而不是单个测试。

And I would argue those chunks should be abstractions, not individual tests.

Speaker 1

这种粒度还是太小了。

That's too small of a chunk again.

Speaker 1

你应该考虑足够大的单元,这样才能权衡利弊,设计出一种通用的解决方案,一次性解决多个问题。

You want to think in a big enough chunk that you can consider trade offs and try and come up with a fairly general purpose solution that will solve many problems.

Speaker 1

顺便说一句,我认为设计中最重要的原则之一,就是尽量逼自己走向通用性,避免过度特化。

By the way, one of the most important elements of design, I think, is pushing yourself towards general purpose, to avoid specialization as much as you possibly can.

Speaker 1

而TDD的做法反而让你专注于写专门的代码来通过每一个测试,而不是去思考一个能一劳永逸解决多个问题的通用方案。

And so the TDD approach encourages you to do something very specialized to pass each test rather than thinking about the general purpose thing that solves many problems in one place.

Speaker 1

明白了。

Alright.

Speaker 0

是的。

Yeah.

Speaker 0

确实如此。

That that is true.

Speaker 0

确实如此。

That that is true.

Speaker 0

事实上,我记得有一次我们搞TDD团队编程,轮流敲键盘,一个人写测试,另一个人让测试通过。

In fact, like, I remember, like, at at some point when we did we did some TDD mobbing where we would pass the keyboards around, then someone would write a test, someone would make it pass.

Speaker 0

那时候感觉有点做作,因为你写代码的时候总得提醒自己:别写这个,别写那个。

We were trying to it felt a bit artificial because when you wrote more code that you needed to come to, like, uh-uh, no, don't write that.

Speaker 0

你写的代码不能只是为了让测试通过。

That doesn't make just just make the test pass.

Speaker 0

所以整个过程显得有点刻意。

So it almost felt a little bit of artificial.

Speaker 0

当然,我也相信在某些场景下,比如业务逻辑特别复杂的模块,或者需要谨慎扩展代码的时候,这种做法可能还是有它的价值,但也许正因如此,它才慢慢变得不那么流行了,现在大家也不太提了。

And and again, like, I've I'm sure there are times and cases where it it could be useful may maybe in a more formal way, maybe where it's more about adding extending additional code where it's, like, very heavy in business logic, maybe maybe that could be a good good fit, but there might be a reason that it kind of slowly, you know, became less popular, and we're we're not talking about it too much these days.

Speaker 0

至少目前是这样。

At least.

Speaker 1

我唯一建议先写测试的情况,是在修复bug的时候。

The one place where I'd recommend writing the test first is when you're fixing a bug.

Speaker 1

我会说,先写一个能检测出这个bug的测试,然后再去修复它。

I would argue write the test that will detect the bug and then fix it.

Speaker 1

不过说实话,我平时其实是有点偷懒的。

Although actually what I typically do is I honestly I kind of cheat on this one.

Speaker 1

我先直接写好修复代码,再为这个修复写个测试,然后把修复代码撤掉,看看测试是不是真的会失败。

I write the fix and then I write the test for the fix and then I back out the fix and make sure the test fails.

Speaker 1

这样我就有把握了,不过说到底,我觉得在修复bug的时候提前写测试确实挺有用的。

So I know that but anyhow, that's one place where I think doing the test early can be useful.

Speaker 0

还有一个你不同意的点,是关于代码注释的。

Now, one more area that you disagreed is comments.

Speaker 0

所以鲍勃说,不出所料,代码里的注释应该越少越好。

So Bob says unsurprisingly that you should have as few comments of the code.

Speaker 0

代码本身就应该能说明一切。

The code should speak for itself.

Speaker 0

你也不完全认同这个观点。

You also did not fully subscribe to this one.

Speaker 1

如果代码真能完全自解释,那当然再好不过了。

If the code could fully speak for itself, that would be wonderful.

Speaker 1

我一点意见都没有。

I would have no objection.

Speaker 1

但现实是,它做不到,而且永远也做不到。

But it can't, and it never will, as far as I'm concerned.

Speaker 1

有很多东西,根本没法直接写进代码里。

There's just so much stuff that can't be described in the code itself.

Speaker 1

我们后来聊到一些例子,他说:看看这段代码,根本不需要注释,对吧?

And we ended up discussing examples where he said, Look at this code, it needs no comments, right?

Speaker 1

我就说:可我这儿有五个问题,代码里完全没解答。

And then I said, Well, here's five questions people have that I don't see answered in this code.

Speaker 1

他听了之后就有点回避这个问题。

And then he kind of hedged about that.

Speaker 1

所以我觉得吧,他对于注释的抵触实在太强烈了。

And so I don't know, he's very, very biased against comments.

Speaker 1

我不明白,他是不是之前有过什么不好的经历。

I'm not sure why, if he had some scarring experience.

Speaker 1

他坚持认为,人们因为过时的注释而被误导所浪费的时间,比因为缺少足够注释而浪费的时间还要多。

And he argues that he I believe he basically said he thinks that people lose more time by being misled by comments that are out of date than time lost because you haven't had adequate comments.

Speaker 1

但这跟我自己的经验完全不一样。

And that certainly is not my experience.

Speaker 0

不,不是说那个

No, no, not the

Speaker 1

有时候注释确实过时了,但这种情况很少,而且即使过时了,里面通常还是有有用的信息。

Occasionally their comments are out of date but rarely and even then there's usually useful information.

Speaker 1

他还说,如果你和别的开发者一起做项目,根本不需要注释,因为大家都把代码记在脑子里了。

And then he also argued that well if you're working on a project that you and other developers work, you don't need any comments because everybody's got it all loaded into their minds.

Speaker 1

我完全不认同这种说法。

And I just don't agree with that.

Speaker 1

也许他的记忆力比我强,但我没法把所有东西都记在脑子里,写完几周后我就忘了代码是干嘛的,所以我需要注释。

Now maybe his mind is better than my mind, but I can't keep everything in my mind and I forget code within a few weeks of when I've written it, so I need those comments.

Speaker 1

所以归根结底,代码本身是没法传达很多信息的。

So the bottom line is there's just a lot of stuff that you can't get from the code.

Speaker 0

那你的评论习惯是怎样的?你一般怎么写注释?

And then what is your kind of approach on like, how do you do comments?

Speaker 0

你倾向于在注释里写些什么内容?

What do you like to put into comments?

Speaker 0

还是说只要觉得有必要,就随手加点,反正多点信息对以后总有帮助?

Or is it just like whenever you feel like it, just put there because it's going be additional information that could help later?

Speaker 1

再说一遍,第一条原则是:注释应该补充代码里看不出来的信息。

Well, again, the number one rule is comments should tell you things that aren't obvious from the code.

Speaker 1

现在网上有很多糟糕的注释,就是把代码里明摆着的东西再重复一遍。

And so, know, there are a lot of bad comments out there where people are basically just duplicating stuff that's obvious from the code.

Speaker 1

这种情况下,根本没必要写注释。

So no need for comments in those situations.

Speaker 1

我在上课带学生做项目时,经常把他们那些多余的注释删掉,跟他们说:这个注释纯粹在复述代码。

And, you know, in my student projects in my class I often take comments out, tell students, This comment just repeats the code.

Speaker 1

你根本不需要写。

You don't need it.

Speaker 1

我觉得注释最重要的地方是在接口上。

I think where comments are most important is for interfaces.

Speaker 1

这一点特别关键,因为接口的假设就是你不希望别人去读你所调用的那段代码,只看接口就够了。

This is where they're really, really important because the assumption of interface is you don't want people to have to read the code of the thing that you're communicating with, talking about, just want to look at the interface.

Speaker 1

光靠函数签名根本没法提供用户使用这个模块所需的所有信息。

And there's simply, it is impossible in the functional signatures of a module to provide all the information people need to use that module.

Speaker 1

所以注释在这里就特别重要。

And so that's where comments are most important there.

Speaker 1

对我来说,这才是最重要的。

To me, that's the most important.

Speaker 1

第二重要的就是给类的成员变量做详细说明。

The second most important thing is documenting the member variables of classes.

Speaker 1

这个必须写得非常详尽。

That needs really extensive documentation.

Speaker 1

至于方法内部,我一般不需要写太多注释。

And then I tend to find that inside methods I don't tend to need a lot of comments.

Speaker 1

因为如果你明白这个方法的目的,代码本身通常就已经很清楚了。

Because if you know what the method's trying to do, the code typically speaks for itself pretty well there.

Speaker 1

我只会在那些比较复杂、或者我是在调试时才发现的意外情况旁边加注释。

I tend to have comments where things are tricky or where there was unexpected stuff I only discovered when there were bugs and things like that.

Speaker 1

很多时候,我的方法内部根本没注释,只有接口层面的说明。

Often my methods won't have any internal comments, they'll just be the interface comment.

Speaker 0

我觉得这场关于注释的争论可能会重新升温,因为AI工具现在生成的代码越来越多,经常直接生成整个方法——你只要提个要求就行。

I think comments are going to have a bit of a resurgence of this debate potentially because AI tools increasingly generate more code, They often generate whole methods, you know, you can ask.

Speaker 0

我发现,当我让AI助手帮我生成某个功能时,它写完代码后,往往会加上行内注释来解释这段代码的作用。

And what I'm noticing is when I when I'm telling, you know, one of these AI assistants, generate something that does this for me, it generates the code, but it often adds inline methods, which explains what it does.

Speaker 0

这种情况下,因为生成得太快了,反而对我有帮助——我知道这些工具容易胡编乱造,所以我得确认它到底在干什么,注释正好帮了我理解。

And actually, that case, because it's just coming so quickly, it actually kind of helps me because I'm I know these tools hallucinate, and I actually want to make sure what it does so it kind of helps me understand.

Speaker 0

但与此同时,这也引出一个问题:它为什么非得加这些注释?

At the same time, it's a good question of why it's doing it.

Speaker 0

你知道吧,这些模型通常是用网上现有的代码训练的,不管是开源的还是别的什么授权的代码。

You know, these are trained on typically code that's out there, either either open source or who knows what kind of licensing.

Speaker 0

所以它很可能就是照搬它见过的那些内容。

So it it probably is copying however it's it's seen it.

Speaker 0

不过一般来说我同意你的看法,但这次我觉得加点注释也未必是坏事。

But you know, usually I would agree with you, but in this case maybe comments are not a bad thing.

Speaker 0

谁知道呢?

Who knows?

Speaker 0

这确实是个挺有意思的话题。

It's an interesting area.

Speaker 1

是的,我有点犹豫说这个,因为我怕自己是在为不良习惯找借口。

Yeah, so I'm a little hesitant to say this because I'm fearing I may be justifying bad habits.

Speaker 1

但我发现,AI工具在某种程度上能弥补注释不足的问题。

But one thing I've found is that AI tools can, to some degree, compensate for the lack of comments.

Speaker 1

我最近在搞 Linux 内核,开发一个新的网络传输层。

So I've been working in the Linux kernel, building a new network transport.

Speaker 1

说实话,Linux内核本身并不是什么糟糕的软件,但在我看来,它的注释实在太少了。

Know, overall, Linux kernel is not a bad piece of software but it's pretty significantly under commented in my view.

Speaker 1

我花大量时间只是想搞清楚Linux里到底在发生什么,接口是怎么设计的,该怎么接入进去。

And I spend a lot of my time just trying to figure out what is going on in Linux, what are the interfaces, how do I hook into this.

Speaker 1

ChatGPT已经成了我最好的帮手。

ChatGPT has become my very best friend.

Speaker 1

它在回答关于Linux内核的问题上特别厉害,很多问题我用谷歌怎么都搜不到答案,它却能搞定。

It's amazingly capable at answering questions about the Linux kernel that I can't answer via Google search or any other way.

Speaker 1

它也不总是对的,有时候会瞎编,但大多数时候是对的;就算错了,也能把我引到正确的方向,让我知道该从哪儿下手去找到答案。

It's not always correct, sometimes it hallucinates, but it's often right and even when it's wrong it typically gets me in the right vicinity and helps me to figure out where to look to figure out how to answer my questions.

Speaker 1

我觉得AI工具确实有帮助,但话说回来,如果Linux开发者肯花一点点时间加点注释,根本不用这么费劲地靠ChatGPT去猜。

So I think the AI tools may be able to help but even saying that, if the Linux developers just spent a little tiny amount of time putting comments in it would have made things so much easier than using ChatGPT to try and figure it out.

Speaker 1

所以我觉得,注释的需求不会彻底消失。

So I don't think the need for comments is going to go away completely.

Speaker 1

我们也不能拿AI当借口,让开发者不去写注释。

And we shouldn't use AI tools as an excuse for people not to write comments.

Speaker 1

至少现在还不是。

At least not yet.

Speaker 0

在播客开始前,你提到你最近还在写代码,这挺有意思的。

So before the podcast, one interesting thing that you mentioned is you are actively writing code.

Speaker 0

实际上,播客结束后,我觉得你会重新投入编程工作。

In fact, after this podcast, I think you're gonna be getting back to to writing code.

Speaker 0

你现在正在做什么项目呢?

What what are you working on right now?

Speaker 0

你提到跟Linux内核有关的事。

You mentioned there's something with the Linux kernel.

Speaker 1

是的。

Yeah.

Speaker 1

我的一位博士生,贝纳尔·蒙特塞里,六七年前完成的博士论文里提出了一种新的传输协议,叫Homa,H-O-M-A,专为数据中心设计,他在论文里展示的结果非常出色。

So one of my PhD students, Benal Monteseri, has his PhD dissertation six or eight years ago developed a new transport protocol called Homa, H O N A, which is intended for use in data centers and the results he got in his dissertation are really fabulous.

Speaker 1

在很多应用场景下,它的速度比TCP快上十到一百倍。

It's 10 to 100 times faster than TCP for a whole lot of interesting cases.

Speaker 0

哇哦。

Wow.

Speaker 1

所以我没有让这个项目像很多博士研究一样昙花一现,而是把它当成自己的使命,看看能不能真正把它推广开来,取代数据中心里一部分TCP的使用。

And so rather than let this just come and go as a PhD project that nobody ever cares about, I've taken it as my own personal project to see if it is actually possible to bring this into widespread use and displace some of the TCP traffic in data centers.

Speaker 1

我已经实现了这个协议的Linux内核版本,现在还在持续优化,并且正在把它提交进内核主线。

So I have developed a Linux kernel implementation of that, which I'm continuing to enhance and I'm now in the process of up streaming that into the kernel.

Speaker 1

我现在主要在处理内核开发者们给我的大量反馈,逐一解决他们指出的问题。

So actually what I'm really dealing with is a whole bunch of comments I've gotten from the Linux kernel developers about this and trying to fix all the problems they pointed out.

Speaker 1

这正好说明了代码审查的价值所在。

Here's an example of code reviews and you know the benefits of all of that.

Speaker 1

今天下午我正准备提交下一轮补丁,不过……

And indeed this afternoon I'm getting ready to submit my next round of patches to And the how how are

Speaker 0

你觉得怎么样?这是你第一次向Linux内核贡献代码吗?还是之前有过相关经验?

you finding is this your first contribution to a Linux kernel or have you previously worked on it?

Speaker 1

是的,这是我第一次参与Linux内核开发,我之前并没有……

Yeah, this is my first involvement with a Linux kernel and I have not How are you

关于 Bayt 播客

Bayt 提供中文+原文双语音频和字幕,帮助你打破语言障碍,轻松听懂全球优质播客。

继续浏览更多播客