Skip to Content
程序员的38堂成长课
book

程序员的38堂成长课

by Pete Goodliffe
January 2022
Beginner to intermediate
314 pages
6h 55m
Chinese
Posts & Telecom Press
Content preview from 程序员的38堂成长课
写更少的代码
25
要诀
让代码每天都比前一天更好。消除你遇到的所有不必要的重复。
请记住下面这条简单的规则:把“清洁”代码的工作和其他的功能性修改分开提交。这样
做能确保在源代码版本控制系统当中有清晰的记录。无缘无故地把代码清洁和功能性修改
放在一起,会让人难以追踪。一旦有
bug
产生,就不容易区分
bug
是源于代码清洁还是功
能性修改。
3.10
 结论
软件的功能性与系统中代码的行数、模块的数量不是呈正相关的。更多的代码绝不意味着
软件具有更多的功能。
如非必要,勿增新代码。写更少的代码,做更有意义的事。
思考题
1.
你是否能够熟练地写出精练的逻辑表达式?你的逻辑表达式有没有因为过于精练而难以
理解?
2.
你认为
C
语言的
三元运算符
(比如
condition ? true_value : false_value
)会让表达
式的可读性提高还是降低?理由是什么?
3.
我们应该避免
复制
/
粘贴式编程
。一段代码在什么情况下应该保持独立?在什么情况下
应该被提取成公有函数?
4.
怎样鉴别僵尸代码?又该如何消除?
5.
有些编码规范要求每个函数的开头要有特定格式的注释文档,你觉得这有用吗?你是否
认为这会导致很多无意义的额外注释?
拓展阅读
4
章描述了如何鉴别和消除大段的多余代码和僵尸代码。
立刻行动
接下来的几天,仔细审阅你的代码,以发现一些冗余、重复和啰唆的代码。尝试消除
这些多余的代码。
26
3
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

管理Kubernetes

管理Kubernetes

Brendan Burns, Craig Tracey
Python应用开发指南

Python应用开发指南

Posts & Telecom Press, Ninad Sathaye
解密金融数据

解密金融数据

Justin Pauley

Publisher Resources

ISBN: 9787115577948