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堂成长课
27
4
删除也是一种优化
我们把美归于简单的事物,
其没有多余的部分,完全符合其目的……
——拉尔夫
沃尔多
爱默生
少即是多
。这已经是老生常谈了,但确实是至理名言。
我做过很多的代码优化,其中有几个任务让我记忆犹新,引以为傲。这几个优化任务都
了大量的无用代码。坦率地讲,删除无用代码让人感觉神清气爽。
战斗故事
关于多余的代码
我曾在一个采用敏捷软件开发的团队中工作,该团队采用极限编程的原则和实践。这
当中就包括一条规则:
YAGNI [You Aren
t Gonna Need It
(你不会需要它)
]
。这是一
个警告:不要写多余的代码,哪怕你
认为
这些代码将来会被使用。如果现在不需要,
就先不要写,等到真正需要的时候再写。
这听上去非常有道理,我们都欣然接受。
但是人非圣贤,孰能无过?有一次,我发现我们的产品在执行某些简单的任务时耗时
太长,而它们本应瞬间完成。造成该问题的原因是,过度实现、被附加了一些额外装
饰以及到处都是钩子以便扩展。最后这些东西都没有被使用,但在当时看来,它们似
乎都有存在的理由。
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