octave-maintainers
[Top][All Lists]
Advanced

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

Re: goto vs. return?


From: Michael Godfrey
Subject: Re: goto vs. return?
Date: Sun, 24 Jan 2016 07:57:45 -0500
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.5.0



On 01/24/2016 05:49 AM, Kozma, Endre wrote:
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
Right! The strict rule should be NO goto's and only one return. This could be stated as
a reminder of good practice with exceptions allowed in special cases.

Michael




reply via email to

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