-
5
pages
-
English
-
Documents
-
2013
Description
design Editor: Martin Fowler ■ ThoughtWorks ■ fowler@acm.org Fail Fast Jim Shore he most annoying aspect of software de- nullsent? A common approach is to return or a default value: velopment, for me, is debugging. I don’t mind the kinds of bugs that yield to a public int maxConnections() {few minutes’ inspection. The bugs I string property = hate are the ones that show up only af-T getProperty(“maxConnections”);ter hours of successful operation, under if (property == null) {unusual circumstances, or whose stack traces return 10;lead to dead ends. }Fortunately, there’s a simple technique that else {will dramatically reduce the number of these return property.toInt();bugs in your software. It won’t re- }duce the overall number of bugs, at }least not at first, but it’ll make most defects much easier to find. In contrast, a program that fails fast willThe technique is to build your software to “fail fast.” throw an exception: Immediate and public int maxConnections() { visible failure string property = Some people recommend mak- getProperty(“maxConnections”); if (property == null) {ing your software robust by work- throw new NullReferenceExceptioning around problems automatically. (“maxConnections property not This results in the software “failing slowly.” found in “ + The program continues working right after an this.configFilePath);error but fails in strange ways later on.
-
Publié par
-
Publié le
03 juin 2013
-
Langue
English