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堂成长课
保持简单
129
要诀
简单的设计要尽可能地小,小到不能再小。
16.1.4
 代码调用路径短
还记得那句著名的格言吗?“
每个问题都可以通过添加额外的中间层来解决
”额外的中
间层能巧妙地掩盖许多复杂的问题,而许多问题甚至就是由不必要的中间层引起的。如果
必须使用一长串的链式函数调用,或者要通过许多级别的
getter
函数、转发机制和抽象层
来访问数据,那你很快就会痛不欲生。这是不合常理的,这种复杂性毫无必要。
简单的设计会减少中间层,并确保需要的功能和数据不会离使用者太远。
简单的设计还避免了不必要的继承、多态性或动态绑定。这些技巧如果适当使用,都是好
东西。但是,如果盲目运用,就会带来不必要的复杂性。
16.1.5
 稳定性
简单设计的一个明确标志是稳定性。代码可以增强和扩展,却不必大量改动。如果随项目
进行,你反复修改一段代码,则说明要么需求非常不稳定(这
确实
会发生,不过是另外一
个问题),要么设计不够简单。
简单的接口往往是稳定的,不会发生太大的变化。你可以用新服务来扩展它们,但不需要
重写整个
API
。当然,这不应该成为一个约束,因为接口并非一成不变。不要让代码过于
僵化——这也不简单。
16.2
 简单代码
简单的代码易于阅读和理解,所以很容易修改。
代码是否简单,很容易受到个人偏好和熟悉程度的影响。有些人发现某些布局习惯用法对
他理解代码有帮助,另一些人则认为这些习惯用法是很大的障碍。
一致性
对简单的代码至
关重要。复杂多变的样式、命名约定、设计方法和文件格式都会对代码造成不必要的混乱。
要诀
一致性能使代码清晰。 ...
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