Please remove ?:
Derek Parnell
derek at psych.ward
Fri Jun 2 10:57:26 PDT 2006
On Fri, 02 Jun 2006 22:57:14 +1000, Lionello Lunesu
<lio at lunesu.remove.com> 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!
>
> L.
>
> (and removing it will free up the "?" for writefln!! :D)
This is hard to read because the author wrote that way. An alternative
could have been ..
value = _T( NoWallCheck ? "0" : "1" );
Or maybe you prefer the long hand format ...
{
char[] temp;
if (NoWallCheck)
temp = "0";
else
temp = "1";
value = _T(temp);
}
Or maybe ...
if (NoWallCheck)
value = _T("0");
else
value = _T("1");
The ?: operator does not have to be obscure or inefficient.
--
Derek Parnell
Melbourne, Australia
More information about the Digitalmars-d
mailing list