if(;){} opinion
Unknown W. Brackets
unknown at simplemachines.org
Sun Feb 26 11:08:13 PST 2006
Honestly, I must agree that I prefer:
if (auto m = foo())
Or even:
if (auto m; foo())
To:
if (m; foo())
Or *most certainly*:
if (m = foo())
We have types everywhere else in the language (although in places we can
leave them off) so it doesn't seem strange here either. I can imagine
wanting, even, to ASSERT that I'm getting an int from the function. If
this changes to a class, my code probably won't work anymore anyway.
-[Unknown]
> Better 'fess up front: the intent of this post is to once and for all
> murder, pulverize and extradite the new if construct.
>
> Consider:
>
> if (m; std.regexp.search("abcdef", "b(c)d"))
> {
> writefln("[%s]", m.pre); // prints [a]
> writefln("[%s]", m.post); // prints [ef]
> writefln("[%s]", m.match(0)); // prints [bcd]
> writefln("[%s]", m.match(1)); // prints [c]
> writefln("[%s]", m.match(2)); // prints []
> }
>
> Flauting this around has shown that experienced programmers have a hard
> time figuring out what is going on here.
>
> Consider:
>
> if (m; std.regexp.search("abcdef", "b(c)d"))
>
> Most everybody take it for granted that here is a typo, the '(m;' must
> be the result of a sloppy copy-paste.
>
> And in the previous case the theories ranged from all kinds of
> behind-the-scenes magic.
>
> Now consider:
>
> if (Regexp m = std.regexp.search("abcdef", "b(c)d"))
> {
> writefln("[%s]", m.pre); // prints [a]
> writefln("[%s]", m.post); // prints [ef]
> writefln("[%s]", m.match(0)); // prints [bcd]
> writefln("[%s]", m.match(1)); // prints [c]
> writefln("[%s]", m.match(2)); // prints []
> }
>
> Flaunting this around (to both the original programmers, and also to
> virgin victims), gave the same, _immediate_ comment from everybody: "Ah,
> that's neat!"
More information about the Digitalmars-d
mailing list