On Friday, January 25, 2013 20:41:01 eles wrote: > You are right. In fact, just after I post the message, I was hit > by second toughts. > > But a issue still remains: assignments of variables are not > usually checked for exceptions. Programmers do not have in mind > that they could trigger exceptions. > > However, properties could do. > > The danger that I see is that programmers will start to > "preventively" check everything for exceptions, "just in case" > that those current variable assignments would be latter turned > into properties. > > Do you feel like embracing all your code in try/catch?
Except that variable assignments _can_ throw, because opAssign could throw. It's true that replacing a variable with a property function which checks its arguments would likely add a new exception to catch, but there's really no way around that. But if the property function checks for stuff which was supposed to be valid before, you changed the semantics anyway, which could be done in a variety of other ways (e.g. making the property function multiply the argument by 7). The reality of the matter is that a property function _isn't_ a variable, just like an overloaded operator isn't the same as using that operator on a built-in type. And the issues are pretty much the same as they are with overloaded operators. But what should be done with try-catch blocks depends on what the code's doing, and if you're having to litter your code with them, you're probably doing something wrong anyway. Still, the possible breakage caused by replacing a variable with a property function which throws is the sort of thing that needs to be considered when making that change. - Jonathan m Davis