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堂成长课
走出泥潭
51
作。这简直就是
代码混沌理论
的典范。有些代码在使用多线程的方式上存在问题:使用不
适当的线程操作原语,或者完全不了解并发条件下如何安全访问系统资源。因为多线程问
题的出现没有规律,所以它们很难被发现、重现和诊断。
(我知道我不应该抱怨。但是很多时候我坚信,在程序员键入
thread
这个词之前,他应该
获得使用这种“危险武器”的许可证。)
要诀
混乱的代码无所不在,要未雨绸缪。准备一些应对它们的法宝,并且
能运用自如。
要想有效地处理这些“异形”代码,需要快速识别问题,并对如何解决问题了如指掌。
7.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