From: James Britt Date: 2006-04-06T13:12:01+09:00 Subject: Re: best practices Jeff Cohen wrote: > For me, this dilemma (long one-liner vs. several short lines) is usually > a sign that I need to refactor. > > I will always take this: > > songs.append(Song.new(title, name, mins.to_i * 60 + secs.to_i)) > > and write it as > > duration = mins.to_i * 60 + secs.to_i > song = Song.new title, name > songs.append song > > then refactor it into > > def append_song(title, name, mins, secs) > duration = mins.to_i * 60 + secs.to_i > song = Song.new title, name > songs.append song > end Where did the 'songs' variable come from? I confess that I'm not so quick to refactor; making three lines into six, with no real gain in clarity, just isn't a compelling case for me. If I find myself repeating code, then sure. But the more common case is a one-off chunk of terse code that can be made more readable with a few intermediary variables. -- James Britt "In physics the truth is rarely perfectly clear, and that is certainly universally the case in human affairs. Hence, what is not surrounded by uncertainty cannot be the truth." - R. Feynman