From: Jim Freeze Date: 2002-03-19T23:03:17+09:00 Subject: Re: style choice > On Tue, Mar 19, 2002 at 10:19:42PM +0900, Ron Jeffries wrote: > > A style question for the community ... which of the following do you prefer, and > > why? Or, if you prefer some third version, what is it and why? > > > > def degree > > return @degree if @degree > 0 > > @scopes.each { | field | @degree += field.length } > > @degree > > end > > > > def degree > > @scopes.each { | field | @degree += field.length } if @degree == 0 > > @degree > > end > I think either of the styles you have given (and the ones posted) are reasonable. I take many things into consideration, such as readability, logic flow, readability by others, speed, extensibility, whether the code is scientific in nature or manipulates text, and so on. Realizing that I am departing from what others have said, I like the second case best because of its conciseness (I like that in my numeric code). I would only alter it if performance was a concern. -- Jim Freeze atto: 1e-18 = one quintillionth parsec: 3.258 light-years: 3.258 * 186000 * 364 * 24 * 3600 * 5280 * 12 attoparsec: atto * parsec =~ 1.20 inch My height: 62 inches / 1.2 = 51.7 attoparsecs ~