Wednesday, November 05, 2008

Return to me......

Of the few readers I have, I estimate that approximately zero are going to understand this post - it's mostly for my own reference, about computer programming style.

At work, our coding standards encourage "at most one return statement from a function", and code review showed my code often has more than one. Finding those places in thousands of lines of code so I can "fix" them might be non-trivial, so I was googling to see if I could find an automatic tool (a good thing to do before deciding to write your own).

Unfortunately, this is a particularly controversial "rule", where probably as many people (including me) think of it as unwise as there are that want to enforce it, so pretty much all I found was just philosophical discussion about one or many exits (same as returns).

One comment I found especially apt (at least in part because he agreed with me that it is better to know when to use a tool then to resolve not to use it:
Your argument that sticking with single exits forces you to factor
your code sounds a little like: "I never use my windshield wipers.
That forces me to stop and clean my car more often, and that is a
good thing." ;)

1 comment:

Joerg said...

I wish I could offer you some help on this, but I try to stick to the old "at most one return statement from a function" most of the time myself.