On Mon, Oct 19, 2009 at 3:45 PM, Mark Miller <markrmil...@gmail.com> wrote:
> but there is some old source code here and
> there that really bugs me

Is it Doug's

  if (foo)
     bar()
  else {
    baz();
  }

or is it my single line

  if (a==null) return 0;

;-)

One of my personal pet peeves is more indentation than necessary for
large blocks of code, rather than just immediately handling the
exception cases and escaping. Example:

void doSomething(MyObj obj) {
  if (obj != null) {    // at this point, I'm wondering... hmmm, is
there code that executes *after* this huge "if" in the event that obj
is null?
      [...]
      // same with this one... ya gotta go and try to match up braces
to see if there is code that executes in the opposite case...
      // and if it also falls through to execute the obj==null case or
simply returns.
      if (some other condition) {
          [ tons of code ]
          [ tons of code ]
      }
  }

A much more readable version (regardless of if one likes the
single-line syntax or not):

void doSomething(MyObj obj) {
  if (obj==null) return;  // immediately obvious handling of the exception case
  [...]
  if (!some other condition) return;  // again, immediately obvious
how the exception case was handled

   [ tons of code ]
   [ tons of code ]
  }


-Yonik
http://www.lucidimagination.com

---------------------------------------------------------------------
To unsubscribe, e-mail: java-dev-unsubscr...@lucene.apache.org
For additional commands, e-mail: java-dev-h...@lucene.apache.org

Reply via email to