It wasn't an efficiency issue (for a change:), it was my other windmill, that of elegance, 'once and once only', duplcated code is two chances to get wrong etc.
Realise that there i no way to avoid (in assembler terms), loading the two values, comparing them, branching if condition not satisfied, do the assignment.
But avoiding the need for the programmer to type the terms twice each as well as the potential for invoking the rvalue expression twice when it could be a volatile function or one with side effects appealled to me.
Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller
| [reply] |
I disagree - I think you need to evaluate the conditional once in scalar or list context, as appropriate, and then evaluate that result in a boolean context. Which implies that if the conditional involves an expensive operation, that operation need only be invoked once.
Of course, people that write clever stuff would need such behaviour documented, but that'd be true whichever approach were selected. And with the entire grammar so mutable, chances are a couple of extra lines in the docs could even show how to avoid this behaviour.
Hugo
| [reply] |