octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: goto vs. return?


From: Kozma, Endre
Subject: Re: goto vs. return?
Date: Sun, 24 Jan 2016 11:49:44 +0100

On Sat, 2016-01-23 at 14:27 -0800, Rik wrote:
According to the Appendix in the manual on Contributing to Octave,

"Avoid comma expressions, labels and gotos, and explicit typecasts. If you need
to typecast, use the modern C++ casting operators. In functions, minimize the
number of return statements—use nested if statements if possible."

Which do we dislike more: goto statements or return from the middle of a
function?

I ask because I count 134 uses of goto in liboctave.  I think most of these
can be avoided now that the error_handler routine no longer returns.  The
others could probably be removed if we used return rather than goto in the
middle of a function.

I personally dislike goto more than return and would remove it, but maybe
there is a consensus in the other direction.

--Rik
If we accept that none of them is the programming attitude to be followed, then there is only one right answer: refactor the whole function.
Such things otherwise are usually good indicators that refactoring is necessary. So you might have to establish multiple smaller functions/methods instead of having a single big one.
The related term is: "clean code".

Endre
reply via email to

[Prev in Thread] Current Thread [Next in Thread]