Restricting ++ and --
bearophile
bearophileHUGS at lycos.com
Sun Oct 25 03:33:13 PDT 2009
This post is born from a bug I've just removed.
In the past I have read more than one C coding standard (or better, lists of coding tips) that warn against bugs caused by ++ and --. They suggest to not use them compound in expressions. They allow to use them when alone on an instruction.
Python designers have totally avoided to put those operators in the language, with the rationale they are bug-prone while saving just a little of typing.
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);
(So ++ and -- become similar to the Inc() and Dec() functions of Pascal).
What problems such changes may cause?
Bye,
bearophile
More information about the Digitalmars-d
mailing list