Increment / Decrement Operator Behavior

bearophile bearophileHUGS at lycos.com
Mon Jun 4 13:44:40 PDT 2012


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 refactor their code. Some 
of the acceptable alternatives are:
1) Make post/pre increments return void. This avoid those 
troubles. I think Go language has chosen this. This is my 
preferred solution.
2) Turn that code into a syntax error for some other cause.
3) Design the language so post/pre increments give a defined 
effect on all D compilers on all CPUs. Walter since lot of time 
says this is planned for D. This leads to deterministic programs, 
but sometimes they are hard to understand and hard to translate 
(port) to other languages any way. Translating code to other 
languages is not irrelevant because D must be designed to make it 
easy to understand the semantics of the code.

Bye,
bearophile


More information about the Digitalmars-d mailing list