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堂成长课
保持外观整洁
11
变得混乱。你的团队只会写出糟糕的代码。
战斗故事
空白之战
我曾经在一个项目当中工作,团队的成员对代码的排版风格毫不在乎。代码一团乱麻,
前后不一,惨不忍睹。我建议团队引入编码规范。
团队成员都认同我的建议,大家认为引入编码规范势在必行。我们就统一命名规则、
代码排版和目录结构达成了一致。这是一个显著的进步,代码开始变得整洁起来。
令人烦恼的是,我们对于一件事争论不休。那就是关于
Tab
和空格
的使用。所有同事
都同意用
4
个空格缩进,但有一个同事坚信用
Tab
缩进更胜一筹。他和队友争吵、抱
怨并且拒绝使用空格缩进。(也许直到现在,他还在和别人争论这个话题。)
因为我们取得了令人瞩目的成果,同时因为害怕无尽的争吵影响士气,所以这个问题
就被搁置了。其他队员用
4
个空格缩进,那位同事坚持用
Tab
缩进。
结果就是代码仍然难以维护、让人抓狂和前后矛盾。光标有时会移动一个空格,有时
会跳得很远。有些工具经过设置,可以正常地显示
Tab
缩进;而有些不能设置
Tab
进长度的工具(我们的版本控制软件和在线代码评审系统就是这样)会让代码变得参
差不齐。
2.4
 命名
矮胖墩儿用轻蔑的口吻说:“我说的那个词儿,
就是我想说的那个意思,无须解释或补充。”
——刘易斯
卡罗尔
在编程中离不开命名,变量、函数、方法、类型(比如枚举和类)、命名空间和包都需要
命名。同样重要的是,还有更大的一些东西需要命名,比如文件、项目和程序。公共的
API
(比如库的接口或者
Web
服务
API
)也需要命名,它的命名是最需要深思熟虑的,因
为一旦发布,就已成定局,很难再有机会修改。 ...
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