Musings on single-point-of-return functions

|

Cedric Beust muses on single-point-of-return functions.

I'm firmly in the single-point-of-return-function camp:

public int dilbert() {

  int result = 0;

  if (...) {

    result = 1;

  }

  return result;

}

It eliminates an else statement - and I strongly dislike them. Plus I'm dead sure that the return value is initialized at least once with a reasonable return value.

However, as long as the function in question is short, using multiple returns is just fine with me. Of course, it may happen that, while looking at the code, I'll refactor it to a single-point-of-return function. Just because my sub-consciousness makes me do it :-)

About this Entry

This page contains a single entry by HMK published on August 4, 2005 4:11 AM.

Design Patterns was the previous entry in this blog.

Transparency... is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.