Please remove ?:

Lionello Lunesu lio at lunesu.remove.com
Fri Jun 2 07:56:28 PDT 2006


Stewart Gordon wrote:
> Lionello Lunesu wrote:
>> I just run accross the following code at my work:
>>
>> #  NoWallCheck?value=_T("0"):value=_T("1");
>>
>> Took at least a minute to figure out what was going on.
>>
>> Please remove ?:... It's useless, slow (just like if/else, but looks 
>> faster since it's so "convenient") and unreadable!
> 
> Useless?  I've put it to plenty of use.  So have many C programmers, 
> some of which have moved on to D.

??? I've multiple inheritance to use, "so have many C++ programmers, 
some of which have moved to D."

By useless I meant that it can be replaced by if/else, so it does not 
fill in a void.

> Slow?  I'm surprised.  Do you have a benchmark?

Just as slow as if/else:

asm {
  cmp x,y
  jne l1
  nop  ;case one
  jmp l2
l1:
  nop  ;case two
l2:
}

It'll always jump.

> Unreadable?  To me, it's certainly more readable than some code.

The if would be more readable. I find it "unreadable", mostly because 
there's not really a limit to what you put between ? and :..

I agree it's handy now and then, but I really would like it to be 
limited to constants or something.

> 
>> L.
>>
>> (and removing it will free up the "?" for writefln!! :D)
> 
> What do you want it to do in writefln?

Remember ? from basic? It's a joke.. nevermind :S



More information about the Digitalmars-d mailing list