From: Josh Cheek on
[Note: parts of this message were removed to make it a legal post.]

On Sat, Jan 9, 2010 at 2:01 PM, Nathan Oyama <nate(a)culip.net> wrote:

> Which one is recommended in terms of the editing style?
>

I usually use braces for single line, and do/end for multi-line.

I've also started alternating them to make it clearer where blocks start and
end.

def whatever
each { |obj|
if obj < MID
call_method
else
self.var = yield obj
call_other_method
end
}
end

def whatever
each do |obj|
if obj < MID
call_method
else
self.var = yield obj
call_other_method
end
end
end

I think the top one is much easier to read, so I sometimes alternate now.

From: Marnen Laibow-Koser on
Josh Cheek wrote:
> On Sat, Jan 9, 2010 at 2:01 PM, Nathan Oyama <nate(a)culip.net> wrote:
>
>> Which one is recommended in terms of the editing style?
>>
>
> I usually use braces for single line, and do/end for multi-line.

That's what 99% of Ruby programmers do. :)

>
> I've also started alternating them to make it clearer where blocks start
> and
> end.
>
> def whatever
> each { |obj|
> if obj < MID
> call_method
> else
> self.var = yield obj
> call_other_method
> end
> }
> end

Yuck! That looks inconsistent to me. It would also be an editing
nightmare if you extract or introduce one level of nesting.

>
> def whatever
> each do |obj|
> if obj < MID
> call_method
> else
> self.var = yield obj
> call_other_method
> end
> end
> end
>
> I think the top one is much easier to read, so I sometimes alternate
> now.

Best,
-- 
Marnen Laibow-Koser
http://www.marnen.org
marnen(a)marnen.org

--
Posted via http://www.ruby-forum.com/.

From: Josh Cheek on
[Note: parts of this message were removed to make it a legal post.]

On Sat, Jan 9, 2010 at 8:34 PM, Marnen Laibow-Koser <marnen(a)marnen.org>wrote:

> > I've also started alternating them to make it clearer where blocks start
> > and
> > end.
> >
> > def whatever
> > each { |obj|
> > if obj < MID
> > call_method
> > else
> > self.var = yield obj
> > call_other_method
> > end
> > }
> > end
>
> Yuck! That looks inconsistent to me. It would also be an editing
> nightmare if you extract or introduce one level of nesting.
>

It's not mandatory, it's mostly just whether they can be lined up easily.
Meaning I would do it if I were having difficulty reading it, so at that
point it can be expected to save me time. If the level of nesting changes,
that doesn't translate into a change between braces and do/end, only if the
introduction makes it difficult to read (meaning they alternate based on
readability rather than every other level of nesting).

From: Nathan Oyama on
Thanks, your all are really helpful!
As a newbie, I will try to write Ruby codes as NORMALLY as possible :)
--
Posted via http://www.ruby-forum.com/.

From: Albert Schlef on
Marnen Laibow-Koser wrote:
> Josh Cheek wrote:
>> def whatever
>> each { |obj|
>> if obj < MID
>> call_method
>> else
>> self.var = yield obj
>> call_other_method
>> end
>> }
>> end
>
> [...] It would also be an editing
> nightmare if you extract or introduce one level of nesting.

Why?

How would you usually add one level of nesting there? (perhaps I could
learn an editing trick.)
--
Posted via http://www.ruby-forum.com/.