Settle a debate. In a code review, I asked that chained assignments be avoided for readability.
What makes line 7 more effective than 8 and 9? Brevity only? I think the long form is more readable and understandable. Does this boil down to preference? Eventually the style guide will need amending, but thought I would post to the board for thoughts.
Thanks, Tim [ May 25, 2004: Message edited by: Timothy Stone ]
Timothy Stone, MIT, SCJP
"This Satan's drink [coffee] is so delicious, we shall cheat Satan and baptize it." --Pope Clement the VIII (1592-1605)
Personally, I go for the long form, as it is easier for me to read. I believe any performance issues are moot, since the assembly code most likely requires the same number of instructions to execute the assignments regardless of how you write them.
As long as the statements are being set to null, or if the variable is a primitive type, I think the only advantage to chaining is brevity. Putting the statements on seperate lines is less confusing, and accomplishes the exact same task.
Of course, if you are creating new objects, chaining them has a very different meaning than assigning on seperate lines. I.E.:
does NOT do the same thing as
(Please correct me if I am mistaken in this!)
“Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.” - Rich Cook