Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

"chained" assignments

 
Timothy Stone
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Settle a debate. In a code review, I asked that chained assignments be avoided for readability.

Given:



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 ]
 
Jeffrey Hunter
Ranch Hand
Posts: 305
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Paul Bourdeaux
Ranch Hand
Posts: 783
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!)
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul you are not mistaken.

Concerning Timothy's question, it's merely a matter of style preference. I think it's a good idea to pick the style that you find more readable.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic