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項必修法則
46
| 第五章:基礎程式的過往陰魂
原始的版本還有另一個問題:重新發明輪子。最佳的做法是直接使用必定存在的
std::max
內建函式。事後看來,這很明顯:[Page-41]
// 不要宣告任何 max 函式
void even_better_example()
{
int a = 3, b = 10;
int c = std::max(a,b);
}
如果重來一次的話,你會避免做這種事情。但是在當時,你不知道典型表達風格是什
麼。
這是一個簡單的範例,但隨著語言增加新的功能(例如 lambda),你現在寫的程式可能
會與之前幾代的程式碼有很大的不同。
設計決策
真的 Perl 來寫那個東西嗎?當時我在想什麼?!我真的使用這種過度簡化的排序演
算法嗎?我真的親自手寫所有的程式碼,而不是使用內建的程式庫?我真的這麼無謂地
將這些類別結合在一起?我真的不能發明一個更乾淨的 API ?我真的將原始碼管理留在
用戶的程式碼中?我可以看到許多潛在的 bug 及漏洞潛伏在那裡!
當你學得更多,就會瞭解有更好的方式可以用程式碼實做你的設計。這是經驗之談。你
犯下一些錯誤、閱讀一些不同的程式碼、與有才華的程式員共事,會很快地發現你的設
計技能已經提升了。
Bug
或許這是讓你回去查看舊基礎程式碼的原因。有時用新鮮的眼光回顧舊程式,會讓你看
到當時錯過的明顯問題。當你被某些類型的 bug 咬過之後(通常常見的典型表達風格會
讓你遠離它們),你自然會開始在舊程式中看到潛藏的 bug。這是程式員的第六感
結論
|
47
結論
遺憾無法彌補生命中的機會被誤用。 ...
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