Regarding the entry "Obfuscating operators" in the doc: I strongly suggest to remove the section and enable the shortcut operators by default. People who do not want to use them don't have to. Giving a opinion as a fact is not very helpful. For me the shortcut operators as in a+=b are more readable than the long a=a+b form. You may want to keep the remark the in CLN there is no performance gain in using the shortcut forms so people who dislike them know they can stick to the long form without a performance penalty. cheers, jj
Hi! Joerg Arndt wrote:
Regarding the entry "Obfuscating operators" in the doc: I strongly suggest to remove the section and enable the shortcut operators by default. People who do not want to use them don't have to. Giving a opinion as a fact is not very helpful. 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. -richy. -- Richard B. Kreckel <http://www.ginac.de/~kreckel/>
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; Bruno
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> rg
* Ron Garret <ron@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
On Jan 22, 2008, at 11:46 PM, Joerg Arndt wrote:
* Ron Garret <ron@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
I'm missing something really basic here. Isn't the >> operator a bitwise-right-shift and hence defined only for integers? rg
Hi! Joerg Arndt wrote:
* Ron Garret <ron@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>
x >> 2 is the same as x / 4.
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.
But it is invalid for floats.
And of course you should use x *= 1.25;
For floats? Sure. For ints it will require the FPU. Besides generating a compiler warning.
The shortcut versions are definitely nicer for the very simple cases as in a += b;
I agree.
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).
It is the use of the FPU which is avoided. That makes it attractive.
Usage as in a += (c *= ++b)>>2 are of course horrible and only indicate the programmer is a l33t wannabe.
Well said. I'm beginning to be convinced that it is best to enable these operators by default. They can be abused, yes. But C/C++ programmers have become so familiar with them that they actually find code using them more readable. -richy. -- Richard B. Kreckel <http://www.ginac.de/~kreckel/>
Hi! Joerg Arndt wrote:
Regarding the entry "Obfuscating operators" in the doc: I strongly suggest to remove the section and enable the shortcut operators by default. People who do not want to use them don't have to. Giving a opinion as a fact is not very helpful. For me the shortcut operators as in a+=b are more readable than the long a=a+b form.
You may want to keep the remark the in CLN there is no performance gain in using the shortcut forms so people who dislike them know they can stick to the long form without a performance penalty.
Okay, I've checked in a patch that removes the need to #define WANT_OBFUSCATING_OPERATORS in CLN 1.2.1 on the ground that, nowadays, such operators are assumed to exist and behave as expected in many template metaprogramming applications. (Well, it's not a big deal to #define it, though. For the record, I've dug out an old email where Bruno justifies this with other eccentricities and spleens, like Linus using his birthday as magic number for the mount syscall. Essentially, the idea is that such quirks are amusing when they are eventually discovered by fellow hackers. Maybe, I should concoct another joke, now.) Cheers -richy. -- Richard B. Kreckel <http://www.ginac.de/~kreckel/>
participants (4)
-
Bruno Haible
-
Joerg Arndt
-
Richard B. Kreckel
-
Ron Garret