I agree with Owen that multiple returns (e.g. checking the validity of arguments first, and returning error codes, before doing the operation) do not hamper the readability of the code. There is clearly a discrepancy in sun's coding style conventions, because exceptions, which are multiple-level returns are allowed to be thrown any number of times in a single unit.

- Milind

On Feb 6, 2007, at 9:31 AM, David Bowen wrote:


Irrational fear of a second return has lead to lots of unnecessary code branches, in my experience. I'd rather see a return early in a function that a nested if branch that includes the rest of the body of the function.

I think it is entirely rational to avoid second returns.  (In cases
where there are a lot of early-exit tests, I would agree that multiple
returns are better than multiple nested if-then-elses.)  However, I
looked up the Sun Java coding conventions and found no mention of this,
so I don't know of any authority to which I can appeal to support my
case.  To me, code is more readily understandable if each unit has a
single exit point.




--
Milind Bhandarkar
(mailto:[EMAIL PROTECTED])
(phone: 408-349-2136 W)


Reply via email to