Skip to Content
成為卓越程式設計師的38項必修法則
book

成為卓越程式設計師的38項必修法則

by Pete Goodliffe
May 2015
Intermediate to advanced
376 pages
5h 48m
Chinese
GoTop Information, Inc.
Content preview from 成為卓越程式設計師的38項必修法則
不好的設計
|
29
不好的設計
當然,沒必要的程式碼並非只是犯下低級的程式碼錯誤或拙劣維護的產物。它也可能是
高級的設計缺陷造成的。[Page-26]
劣質的設計,可能會在元件之間產生許多沒必要的通訊路徑—許多不知道原因的資料管
理程式。資料被傳送得愈遠,就愈有可能在半途損壞。
程式碼元件會隨著時間變得愈來愈囉嗦,或變得與原本的用途全然不同,留下一堆用不
到的程式碼。發生這種情況時,勇敢地清除所有的枯枝,將舊的元件換成較簡單、可完
成必要工作的元件。
設計時,應該先考慮現成的程式庫是否已經有可以解決編程問題的程式了。使用這些程
式庫可以免於編寫一大堆沒必要的程式碼。此外,還有一個紅利,受歡迎的程式庫通常
很可靠、可擴充,而且很好用。
空白字符
別害怕!我不是要攻擊空白字符(也就是空格、tab 及換行)。空白字符是好東西,別害
怕使用它們。如同在讀詩時適當地暫停,合理使用空白字符也可以協助我們架構程式碼。
使用空白字符並非總是產生誤導或沒必要,只是你可能使用太多這種好東西了—在函式
之間使用 20 個換行或許有點過份。
請你考慮使用括弧來將邏輯架構群組化。有時括弧可以協助你釐清邏輯,即使它們不是
被用來防止運算符順序錯誤也是如此。但有時它們是沒必要且礙事的。
那我們該做什麼?
平心而論,通常這種累贅的程式碼不是被故意寫出來的。很少有人會故意寫費力、重
覆、沒意義的程式碼。(但有一些懶惰的程式員會不斷地選擇廉價的路線,而不是花更
多時間,編寫漂亮的程式碼。)大部分情況下,這些問題會發生在已被許多人長期維護、
擴充、使用及除錯的舊版程式碼上面。 ...
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

精通機器學習|使用Python

精通機器學習|使用Python

Sarah Guido, Andreas C. Mueller
Java性能优化实践:JVM调优策略、工具与技巧

Java性能优化实践:JVM调优策略、工具与技巧

Benjamin J. Evans, James Gough, Chris Newland

Publisher Resources

ISBN: 9789863475699