Restricting ++ and --

Peter C. Chapin pcc482719 at gmail.com
Sun Oct 25 04:43:27 PDT 2009


bearophile <bearophileHUGS at lycos.com> wrote in
news:hc19h9$ih1$1 at digitalmars.com: 

> 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++;

In C++, at least, I have often seen recommendations that say post 
increment/decrement should be avoided in favor of pre increment/decrement. 
The rational is that overloaded pre increment/decrement can be implemented 
more efficiently for complicated types---there is no need to create a 
temporary (you mutate the object and then return a reference to that same 
object). Thus I've trained myself to use pre incremenet/decrement 
throughout my C++ code except in cases where I explicitly need the post 
versions.

Of course what's good for C++ does not have to be good for D. However, 
deprecating the pre versions might turn off some potential D converts from 
the C++ community.

Peter



More information about the Digitalmars-d mailing list