if(;){} opinion

David Medlock noone at nowhere.com
Thu Mar 2 09:07:41 PST 2006


Georg Wrede wrote:

> David Medlock wrote:
> 
>> Georg Wrede wrote:
>>
>>> 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.
>>>
> 
>>
>> I would say extend the with(...) construct to silently fail( and take 
>> an else clause ) if the object of the with statement is null.
> 
> 
> if (m; std.regexp.search("abcdef", "b(c)d"))
> {
>    writefln("Yippee!");
> }
> else
> {
>    writefln("Bad-ee.");
> }
> 
> works already.
> 
> (Replace "abcdef" with "abXdef" to see.)

It may work but you are making a new nest of corner cases with a known 
programming construct with specific behavior.

Looks as if one mistyped semicolon could introduce very interesting 
behavior...

-DavidM




More information about the Digitalmars-d mailing list