My First patch

Dirk Hohndel dirk at hohndel.org
Sat Mar 1 12:52:13 PST 2014


Let me be a little more forceful here :-)

On Sat, 2014-03-01 at 21:32 +0200, Lubomir I. Ivanov wrote:
> > I am sending this,as an improvement to the existing code since
> > goto is not preferred as a reliable keyword in software development process.
> >
> 
> goto is perfectly fine in a lot of cases and doesn't obfuscate the
> code that much if used wisely.
> as you can see your patch removes 3 lines, but adds 6.

goto is often a much BETTER way to write good, clean code.
I understand that many people stuck teaching computer science classes
with no actual practical development experience hate goto on principle
and teach the same to their students, but the reality is that very often
using a forward goto to an exit condition is by far the best and
cleanest way to create easy to understand, easy to maintain, easy to
debug algorithms.

Subsurface will not accept code with backward gotos. Those are indeed a
sign that something is wrong with your code. But well placed forward
gotos with meaningful labels are not only accepted but actually welcomed
in our code. The goal is readability and clarity.

If you look at the code before and after your change you'll see that you
added duplicate code - so if we need to make a change to the code at the
end of the loop (because we want to set some flag or some other
variable) we now need to remember to do this in two places.

> > I can change the logic regarding goto in all the cpp files in the existing
> > codebase. I am good at C++, so I am sure that I will not disturb the logic
> > part.

I'm sure you can. But unless you find cases in which the goto makes the
code harder to understand or maintain I would ask you not to do that.

/D




More information about the subsurface mailing list