On 12/11/2012 4:06 PM, bearophile wrote:
Plus one or two switches to disable such checking, if/when someone wants it, to
regain the C performance. (Plus some syntax way to disable/enable such checking
in a small piece of code).
I.e. the C# "solution".
1. The global switch "solution": What I hate about this was discussed earlier
today in another thread. Global switches that change the semantics of the
language are a disaster. It means you cannot write a piece of code and have
confidence that it will behave in a certain way. It means your testing becomes a
combinatorial explosion of cases - how many modules do you have, and you must
(to be thorough) test every combination of switches across your whole project.
If you have a 2 way switch, and 8 modules, that's 256 test runs.
2. The checked block "solution": This is a blunt club that affects everything
inside a block. What happens with template instantiations, inlined functions,
and mixins, for starters? What if you want one part of the expression checked
and not another? What a mess.
Maybe someday Walter will change his mind about this topic :-)
Not likely :-)
What you (and anyone else) *can* do, today, is write a SafeInt struct that acts
just like an int, but checks for overflow. It's very doable (one exists for
C++). Write it, use it, and prove its worth. Then you'll have a far better case.
Write a good one, and we'll consider it for Phobos.