request switch statement with common block

H. S. Teoh hsteoh at quickfur.ath.cx
Sat Aug 3 12:35:22 PDT 2013


On Sat, Aug 03, 2013 at 12:22:53PM -0700, Walter Bright wrote:
> On 8/3/2013 12:00 PM, JS wrote:
> >What I really don't get it is why people think that just because they
> >won't use such a feature then it must be useless to everyone else.
> 
> You could provide supporting evidence by examining every use of
> switch in the dmd, phobos, and druntime source code, and see what
> percentage of those would benefit from your proposal.
> 
> Consider, for example, the scope guard statement in D. It is
> extremely useful - but it is an unusual form (doesn't exist in other
> languages) and programmers just don't think in those terms. Andrei &
> I constantly have to work at 'selling' the benefits of it. It still
> hasn't really caught on.

At least it has caught on with me. :) After learning about scope guards
in D, I've been plagued with persistent thoughts of "I wish I could use
a scope guard here!" every time I work with C/C++ code.

Ironically, though, D's superior design has pretty much eliminated the
need for scope guards except in a few rare cases. :-P  They used to be
still useful for things like closing files at the end of the block, but
struct dtors have pretty much eliminated that use case as well.

But I'd venture to say that in code that uses manual memory management
(like game engines), scope guards are a lifesaver. Maybe Manu can chime
in here. :)


T

-- 
The best compiler is between your ears. -- Michael Abrash


More information about the Digitalmars-d mailing list