static try?

Don nospam at nospam.com
Wed Nov 2 05:25:53 PDT 2011


On 02.11.2011 09:38, Mehrdad wrote:
> On 11/1/2011 11:55 PM, Don wrote:
>> On 31.10.2011 02:21, Mehrdad wrote:
>>> I've written this piece of code a fair number of times:
>>>
>>> static if (is(typeof(foo()))) { foo(); }
>>> else { bar(); }
>>>
>>> When the expression inside the condition (i.e. the call to foo()) gets
>>> complicated, you get lots of code duplication and things become harder
>>> to read.
>>
>> IMHO the only problem is the is(typeof()) syntax.
>> Otherwise I don't see how this has any more code duplication than:
>>
>> if( foo(lots_of_parameters) )
>> foo(lots_of_parameters);
>> else bar();
> Huh?
>
> sorry but I'm confused as how that's related to static try/catch...

The only benefit you'd get from static try/catch is a small reduction in 
code duplication, in one specific idiom. I'm arguing that the code 
duplication is no worse in this case than in anything other case in the 
language. I'm not seeing why that particular idiom is so phenomenally 
important that it deserves its own syntax to obtain such a tiny benefit.


More information about the Digitalmars-d mailing list