Impressed

Nick Sabalausky SeeWebsiteToContactMe at semitwist.com
Thu Jul 26 19:41:06 PDT 2012


On Fri, 27 Jul 2012 04:09:36 +0200
"Stuart" <stugol at gmx.com> wrote:

> On Friday, 27 July 2012 at 01:45:35 UTC, Jonathan M Davis wrote:
> > Now, we have way more safe constructs for moving around in code 
> > then was the case when goto was originally vilified,
> > and everyone is using those constructs rather than goto.
> > But the stigma remains and everyone is used to thinking of goto 
> > as evil.
> 
> So if everyone uses these other constructs, why even provide a 
> goto? I seriously have not needed a goto in over ten years; and 
> the way I see it, if your program uses one, it needs to be 
> refactored. Just my opinion.
> 
> > It's a useful construct when used properly. It just shouldn't 
> > be used when
> > there are better alternatives.
> 
> I can't think of ANY situation where goto would be the only 
> viable option. Loops, ifs, switches - these cover 100% of 
> requirements, surely? If it really is necessary in some cases, 
> how have I managed to avoid goto for so long? And what are these 
> cases?


Duff's device.

Goto certainly should not be used (except for "goto case") in the vast
majority of cases. And it is indeed extremely rare to find goto used in
D code. Plus having it in existence doesn't really cause problems - only
abusing it causes problems and but nobody really abuses goto anymore
anyway. But there are some rare controlled cases (like duff's device,
or porting old C code that might use it) where some low-level
programmers do consider it to be useful (whether right or wrong). So
it's there if for whatever reason you happen to need it, otherwise it
just stays out of the way and doesn't bother anybody.



More information about the Digitalmars-d mailing list