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項必修法則
156
| 第十六章:保持簡單
充分簡單
簡單度與
充分度
是好朋友。這在幾個方向可看出:
y
你應該採用最簡單的工作方式,並編寫最簡單的程式。但讓它充分簡單。如果你過
度簡單,你將無法解決實際的問題。我們的“簡單”解決方案
必須
“充分”,否則
它們就不是解決方案。
y
只編寫足夠解決問題的程式。不要編寫大量你
認為
將會用得到的程式。不會被用
到的程式只是包袱。它是額外的負擔。那是你不需要的複雜度。編寫足夠數量的程
式。你寫的程式愈少,你製造的 bug 也會愈少。
y
不要將解決方案複雜化,激動的開發人員會認為這是非常真實的誘惑。只要解決手
頭的問題,不要為了一堆不相干的問題,發明不需要的通用解決方案。一直工作,
直到充分性達到燦爛的地步。
重點
編寫需要的程式。任何多出來的部分,都只是造成負擔的複雜度。
簡單的結論
我們都知道完美的簡單程式比沒必要的複雜程式還要好。而且我們都看過骯髒的、醜陋
的、複雜的程式。很少有人想要寫這種程式。前往複雜度的道路上,通常遍布匆忙的改
變與打滑的標準。只要有一個鬆懈的修改、只要有一個狗皮藥膏修補、只要有一次程式
檢查被跳過、只要有一次“我沒有時間重構”,這些原因夠多的話,程式就會變成一團
亂,你會很難讓它恢復理智。[Page-150]
可悲的是,簡單化很難做到。
簡單化是由許多受歡迎的開發人員格言產生的標語布條:YAGNI
you aren't going to
need it
說的是充分性。DRY
don't repeat yourself
說的是程式大小。說到設計的簡單
性,我們偏好高內聚與低耦合的做法。 ...
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