Re: [Hampshire] Code style

Top Page

Reply to this message
Author: Daniel Pope
Date:  
To: Hampshire LUG Discussion List
Subject: Re: [Hampshire] Code style
Vic wrote:
> Style A has multiple returns from the function. That's one of those things
> that's just fine right up until it isn't; code grows as different people
> work on it, and sooner or later, you can't see both returns on the same
> page. That's when mistakes happen.


Totally disagree with that. When one path has a result, it's much
clearer to dump it out of the function straight away which makes it
obvious that code path is finished. Otherwise you end up with multiple
code paths to consider throughout the rest of the function.

It may also requires fewer temporary variables which also reduces the
amount I have to hold in mind at the same time when reading code. Humans
can only hold around 7±2 things in mind at once and I prefer them not to
be the names of redundant temporary variables.

It may also require fewer conditionals to maintain state in the rest of
the function, so it ends up as fewer lines of code, and hence more readable.

Dan