assignment: left-to-right or right-to-left evaluation?

Christopher Wright dhasenan at gmail.com
Tue May 12 04:14:56 PDT 2009


Michiel Helvensteijn wrote:
> Jarrett Billingsley wrote:
> 
>> It's
>> incredibly rare that I have to assign the same value to multiple
>> targets, and when I do, the little time I could save by not typing the
>> second assignment is offset by the increased time it takes me to look
>> for assignments to a variable when I come back to the code later.
> 
> It's not about time. It's about code duplication.
> 

Code duplication is only an issue when it can be a maintenance problem. 
Repeating the name of a temporary variable in five consecutive 
assignments is not a maintenance problem.

A preference for or against assignment chaining is mainly stylistic. The 
exception is when you reference the same variables in the LHS as the RHS 
and modify them in one of the locations -- this gets confusing, even 
with a specified order.

For that reason, I always use the ++ and -- operators as statements. 
Other people can use them as expressions and not get confused, but I 
always have to take a moment to think about which value will get 
returned. It only takes a moment, but I prefer not having to spend 
thought on such trivial matters when I'm reading code.



More information about the Digitalmars-d mailing list