www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Re: Restricting ++ and --

reply Kagamin <spam here.lot> writes:
bearophile Wrote:

 Removing those operators from D, as Python, may look excessive. So a possible
compromise can be:
 - Deprecate the pre versions:  --x  and ++x
 - Make them return void, so they can't be used as expressions like this:
 y = x++;
 foo(x--);
 You have to use them as:
 x++; y = x;
 x--; foo(x);

int PreInc(ref int i){ i++; return i; } int PostInc(ref int i){ i++; return i-1; } y=PreInc(i); y=PostInc(i); just a little more difficult. y=x=0; Ever wondered what opAssign returns?
Oct 26 2009
parent bearophile <bearophileHUGS lycos.com> writes:
Kagamin:

 int PreInc(ref int i){ i++; return i; }
 int PostInc(ref int i){ i++; return i-1; }
 y=PreInc(i);
 y=PostInc(i);
 
 just a little more difficult.

That's a vote for my proposal then, because you have shown a way to do the same thing for people that really need to do it. In D there are often ways to do everything. To help avoid bugs there's no need to totally remove all ways to do something, but to turn them into something explicit and under programmer's control. The idea is to turn places where possible bugs can be hidden into something that can be seen. Bye, bearophile
Oct 26 2009