On Fri, 27 Jul 2012 15:09:14 +0100, Kagamin <s...@here.lot> wrote:

On Friday, 27 July 2012 at 14:03:05 UTC, Marco Leise wrote:
Also when I have a sequence of steps to be done and some steps may jump back a few steps, I prefer labels with good names + goto, over blocks of for/while/if, which distract from the sequential nature of the code.

Huh, but such code is not sequential, it's spaghetti.

Spaghetti goes in many directions, the code above always flows downhill but sometimes jumps/loops back up. As long as the jumps are in one direction and not both, it's typically easy enough to follow.

IMO, goto is a tool like any other, in the wrong hands it can make bad code, in the right hands, used sparingly and only when it makes code easier to follow it's the right tool and avoiding it due to dogma is just plain silly.

My main use in the past has been to jump to clean up code, which is not always necessary with D as we have finally and scope(exit).

If I have the choice between a loop construct which only ever executes once with 'break' to simulate goto vs using goto, I will chose the latter because it's clearer what the intent of the code is, it actually makes the code cleaner and easier to follow.

I tend to code in the style of check for error and fail/return/exit vs layered scopes (if inside if inside if ..) because the flatter the code the easier I find it to reason about code paths and logic, goto can help to keep a piece of code flat and make it easier to reason about.

I almost always use goto to jump down a function, and almost never up. Loop constructs are with 'continue' are a better match for the latter.

R

--
Using Opera's revolutionary email client: http://www.opera.com/mail/

Reply via email to