[CLN-list] doc: "Obfuscating operators"

Joerg Arndt arndt at jjj.de
Wed Jan 23 08:46:02 CET 2008


* Ron Garret <ron at flownet.com> [Jan 23. 2008 14:17]:
>
> On Jan 22, 2008, at 3:07 PM, Bruno Haible wrote:
>
>> Richard B. Kreckel wrote:
>>>> For me the shortcut operators
>>>> as in a+=b are more readable than the long a=a+b form.
>>>
>>> I do admit that I find the shortcuts more readable, too.
>>
>> I think it depends. When you are summing up a power series,
>>
>>   sum += factor/(2*n+1)
>>
>> makes perfect sense. But I also have seen things like this:
>>
>>   x += x >> 2;
>>
>> which really is less readable than
>>
>>   x = 1.25 * x;
>
> <puzzlement> Don't those two statements do different things? </puzzlement>

yes-ish:
the first should rather be used for integers (as a matter of style).

If used for floats then
x += x >> 2;  // x = 1.25 * x;
shows that comments are useful indeed.

And of course you should use
x *= 1.25;

  8-))


The shortcut versions are definitely nicer for
the very simple cases as in  a += b;

In the case  x += x>>2;  (assume x integer) one might argue that
a temporary is avoided to make the code more readable (ignoring
what the compiler generates).

Usage as in
 a += (c *= ++b)>>2
are of course horrible and only indicate the programmer is a l33t wannabe.

>
> rg

cheers,   jj


More information about the CLN-list mailing list