blog.jj5.net (2003 to 2005)

Help! Help! I'm addicted to return!

Fri Apr 30 17:27:00 UTC+1000 2004

Categories:

My new favorite way to code is with testing for the 'exceptional' case first and then aborting processing, allowing the 'typical' case code to be outside of any conditional block. So, for example I used to have a method that looked like this:

if (!something) {
  // do some work
}

But now I'd write the same method like this:

if (something) {
  return;
}

// do some work

Is someone going to accuse me of branching evilness akin to 'goto'..? :)

John.


Copyright © 2003-2005 John Elliot