From: Holden Glova Date: 2002-03-20T17:17:13+09:00 Subject: Re: style choice -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Wed, 20 Mar 2002 01:53, David Alan Black wrote: > Hello -- > > On Tue, 19 Mar 2002, 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 > > Interesting -- I'm not as anti-if-modifier as some, but here, maybe > because of the length of the pre-if part, I like the first one better. > > My instincts, such as they are, might lead me to do: > > def degree > if @degree == 0 > @scopes.each {|field| @degree += field.length} > end > @degree > end > > I'm a bit stuck on the "why" part :-) > > > David Door #1 I don't like because of aesthetics perhaps, I see one return statement, yet there are 2. I'm also not sure about the early bail out, but i'm not quite sure why, sorry.... Door #2 I almost like this one except that the block is used with an if modifier. I prefer to the block to at least be enclosed with an if block in case I choose to 1) extend the if statement to span more then one line then it's just easier and 2) if I choose to extend what happens in the block then I can easily make that span multiple lines while still looking like conventional Ruby to me. Door #3 I like this one becuase it addresses 1 & 2 as defined behind Door #2 :) - -- Signed, Holden Glova -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.6 (GNU/Linux) Comment: For info see http://www.gnupg.org iD8DBQE8mEa5+mF116Lw2cQRAjyHAKCHd9t8lDiyo/eeeyxamNs1lqSiKgCfXeqx G+4pl98T9dgiucz5yB+A1pA= =Pm73 -----END PGP SIGNATURE-----