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項必修法則
第九章
未雨綢謬
做好準備…座右銘的意思是,
童子軍必須未雨綢繆,並練習意外或
緊急狀況發生時該採取的行動,
做好準備,讓自己永遠不會措手不及。
- Robert Baden-Powell
有人說,有些人看到的是半滿的杯子,有些人看到的是半空的杯子。但大部分的程式員
完全不會看到杯子,他們在寫程式時,不會考慮不尋常的狀況。他們既不是樂觀的人,
也不是悲觀的人。他們甚至不是現實主義者。他們是漠視主義者。
在編寫程式碼時,不要只考慮預期發生的情況。請在每一個步驟,考慮所有可能發生的
意外情況,無論你認為它們多不可能發生。
錯誤
你所呼叫的任何函式,都有可能會不如你預期地動作。
y
如果幸運的話,它會回傳一個錯誤碼來提醒你。若是如此,你應該檢查它,不要忽
視它。
y
如果函式無法履行合約,它可能會丟出例外。確保你的程式碼可處理它丟出的例
外。無論你要捕捉例外並處理它,或是在呼叫堆疊中將它傳出去,確保你的程式碼
是正確的。正確包括不要洩漏資源,或讓程式處於無效狀態。
76
| 第九章:未雨綢謬
y
函式也有可能不會回傳錯誤的指示,但不如你所預期地保持安靜。當你要求函式印
出訊息時,它一定會印出來嗎?它是否可能失敗,並吃掉訊息? [Page-70]
你一定要考慮可以恢復的錯誤,並編寫合適的恢復程式。也要考慮無法恢復的錯誤。儘 ...
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