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堂成长课
16
3
相反的作用。这些代码不易于修改和维护,并且会导致很多错误,以至于影响用户体验。
它们就是编程中的反物质。
要诀
更少的代码有时候意味着更多的软件。
我的很多引以为傲的软件优化任务是通过删除代码实现的。让我记忆犹新的是,我曾在一
个枝蔓丛生、野蛮生长的系统中一次删掉了上千行代码,而仅用十多行简单的代码就实现
了完美的替换。那种感觉真是让人心旷神怡。我建议你有机会尝试一下。
3.1
 为什么要关注
为什么不能保留多余的代码,仅仅是因其招人厌烦吗?
有很多事实可以证明,多余的代码简直就是万恶之源,以下是几个要点。
创造一行新的代码就像见证一个生命的诞生。它需要被精心抚育,使之能为软件系统做
出巨大的贡献,之后才能被发布和使用。
在软件系统的生命周期中,代码需要维护。每一行代码都需要花费精力维护。代码编写
得越多,维护耗费的精力就越多。代码存在的时间越长,它所耗费的精力也就越多。显
而易见,多余的代码应该及时清除,以免其消耗我们太多的精力。
更多的代码需要更多的时间和精力去阅读和理解,这让我们的程序更加难以领会。多余
的代码会掩盖一个函数的意图,也会隐藏相似的代码之间微小但重要的差异。
更多的代码会导致修改的工作量增大,从而使程序难以修改。
代码当中隐藏着
bug
。代码越多,
bug
就有越大的藏匿空间。
重复代码贻害最深。你修复了一段代码中的一个
bug
,但是不会知道,还有
32
个同样
bug
已经随着代码的重复散布在各处。
多余的代码是代码中的“不法分子”,它会以多种形式出现:无人使用的模块、僵尸代码、 ...
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