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堂成长课
30
4
要诀
尽可能清除僵尸代码。僵尸代码会妨碍你,拖慢你的步伐。
4.4
 唤醒梦中人
怎样找到僵尸代码呢?
最好的办法就是在编写代码时集中注意力。注意你编写代码时的一言一行,确保每次修改
之后,都不忘清理无用代码。定期的代码评审也可以让僵尸代码无所遁形。
如果你想定位所有未使用的代码片段,有很多很棒的代码覆盖率检测工具可供使用。
1
好的
IDE
,特别是静态语言的
IDE
,能够自动高亮显示未使用的代码片段。对于公有
API
,很
IDE
有“发现引用”的功能,可以查看
API
的调用情况。
如果要定位那些用户从不使用的功能,那么可以在产品中加入信息收集器,收集关于用户
实际使用情况的各项指标。这不仅可以发现用户从不使用的功能,而且对于做出业务决策
同样很有价值。
4.5
 动个手术吧
清除僵尸代码有百利而无一害。不要踟蹰不前,坚决去做吧。这又不是外科手术,切掉了
就接不回来了。如果有一天你发现需要那些被清除的代码,那么可以轻而易举地把它们从
版本控制系统里找回来。
要诀
删除以后
可能
要用的代码是安全的。你随时可以把它们从版本控制系
统里找回来。
对于这个简单而正确的观点有反对的声音:如果不知道一段代码之前存在于某处,那么一
个新员工如何知道删除的代码可以在版本控制系统里找到呢?怎样才能阻止他们自己造
(有
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