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 ­čÖé

Comments are closed.