Re: Increment / Decrement Operator Behavior

2012-06-06 Thread Dejan Lekic
On Tue, 05 Jun 2012 10:23:18 +0200, Mikael Lindsten wrote: 2012/6/5 Jonathan M Davis jmdavisp...@gmx.com I think that Bernard is being a bit harsh, but in essence, I agree. Since the evaluation order of arguments is undefined, programmers should be aware of that and code accordingly. If

Re: Increment / Decrement Operator Behavior

2012-06-06 Thread Iain Buclaw
On 4 June 2012 23:37, Jonathan M Davis jmdavisp...@gmx.com wrote: On Monday, June 04, 2012 23:22:26 Bernard Helyer wrote: On Monday, 4 June 2012 at 20:44:42 UTC, bearophile wrote: Bernard Helyer: If you find yourself using postfix increment/decrement operators in the same function call in

Re: Increment / Decrement Operator Behavior

2012-06-05 Thread Timon Gehr
On 06/04/2012 08:36 PM, Xinok wrote: The increment and decrement operators are highly dependent on operator precedence and associativity. If the actions are performed in a different order than the developer presumed, it could cause unexpected behavior. I had a simple idea to change the behavior

Re: Increment / Decrement Operator Behavior

2012-06-05 Thread Mikael Lindsten
2012/6/5 Jonathan M Davis jmdavisp...@gmx.com I think that Bernard is being a bit harsh, but in essence, I agree. Since the evaluation order of arguments is undefined, programmers should be aware of that and code accordingly. If they don't bother to learn, then they're going to get

Re: Increment / Decrement Operator Behavior

2012-06-04 Thread simendsjo
On Mon, 04 Jun 2012 20:36:14 +0200, Xinok xi...@live.com wrote: The increment and decrement operators are highly dependent on operator precedence and associativity. If the actions are performed in a different order than the developer presumed, it could cause unexpected behavior. I had a

Re: Increment / Decrement Operator Behavior

2012-06-04 Thread Bernard Helyer
If you find yourself using postfix increment/decrement operators in the same function call in multiple arguments, slap yourself firmly in the face and refactor that code.

Re: Increment / Decrement Operator Behavior

2012-06-04 Thread simendsjo
On Mon, 04 Jun 2012 20:57:11 +0200, simendsjo simend...@gmail.com wrote: On Mon, 04 Jun 2012 20:36:14 +0200, Xinok xi...@live.com wrote: The increment and decrement operators are highly dependent on operator precedence and associativity. If the actions are performed in a different order

Re: Increment / Decrement Operator Behavior

2012-06-04 Thread Xinok
On Monday, 4 June 2012 at 20:08:57 UTC, simendsjo wrote: Oh, and what should writeln(i++, ++i, ++i, i++) do? It is messy whatever the logic implementation. For prefix operators, it would be logical to perform the action before the statement, such as the code would be rewritten as: ++i ++i

Re: Increment / Decrement Operator Behavior

2012-06-04 Thread bearophile
Bernard Helyer: If you find yourself using postfix increment/decrement operators in the same function call in multiple arguments, slap yourself firmly in the face and refactor that code. I think this is not acceptable, you can't rely on that, future D programers will not slap themselves and

Re: Increment / Decrement Operator Behavior

2012-06-04 Thread Bernard Helyer
On Monday, 4 June 2012 at 20:44:42 UTC, bearophile wrote: Bernard Helyer: If you find yourself using postfix increment/decrement operators in the same function call in multiple arguments, slap yourself firmly in the face and refactor that code. I think this is not acceptable, you can't rely

Re: Increment / Decrement Operator Behavior

2012-06-04 Thread Jonathan M Davis
On Monday, June 04, 2012 23:22:26 Bernard Helyer wrote: On Monday, 4 June 2012 at 20:44:42 UTC, bearophile wrote: Bernard Helyer: If you find yourself using postfix increment/decrement operators in the same function call in multiple arguments, slap yourself firmly in the face and refactor

Re: Increment / Decrement Operator Behavior

2012-06-04 Thread bearophile
Jonathan M Davis: If they don't bother to learn, then they're going to get bitten, and that's life. A modern language must try to avoid common programmer mistakes, where possible (like in this case). As for treating pre or post-increment operators specially in some manner, that doesn't

Re: Increment / Decrement Operator Behavior

2012-06-04 Thread Xinok
On Monday, 4 June 2012 at 20:44:42 UTC, bearophile wrote: 1) Make post/pre increments return void. This avoid those troubles. I think Go language has chosen this. This is my preferred solution. I wonder in that case, is it even worth including in the language? For me anyways, the whole point

Re: Increment / Decrement Operator Behavior

2012-06-04 Thread Kevin Cox
On Jun 4, 2012 8:43 PM, Xinok xi...@live.com wrote: I wonder in that case, is it even worth including in the language? For me anyways, the whole point of these operators is to use them in expressions. Otherwise, why not simply write (i+=1)? For pointers they are useful because they go up in