From: ara.t.howard@... Date: 2006-04-06T06:34:12+09:00 Subject: Re: best practices On Thu, 6 Apr 2006, Jean-Charles Carelli wrote: > I'm working my way through the Pickaxe book and I have a question regarding > syntax and best practices. > > Example from page 64 > > # 1 Book example > songs.append(Song.new(title, name, mins.to_i * 60 + secs.to_i)) > > > # 2 Alternate version. > duration = mins.to_i * 60 + secs.to_i > songs.append(Song.new(title, name, duration)) > > > Version 1 is very concise but harder to read. Ruby is very intuitive but I > find the second example easier to read. What is everyone else doing? sometimes i warp a bunch of lines into one, but in production code i tend to do this: duration = mins.to_i * 60 + secs.to_i song = Song.new title, name songs.append song otherwise it can be difficult to interpret stack traces with line numbers. consider songs.append(Song.new(title, name, duration)) this can throw in Song.new or append - but both are on the same line. using a duration tmp var is also very self doccumenting. i guess it all just depends on the application and context of the code being written. regards. -a -- be kind whenever possible... it is always possible. - h.h. the 14th dali lama