Indenting "end"

I’ve been seeing a lot of this lately:

def foo(bar)
  puts bar
  end

For me, at least, this tends to make code kind of difficult to read.
This is what I’ve always seen in Ruby code before recent trends:

def foo(bar)
  puts bar
end

Is this some kind of bleed-over from Python’s lack of ending delimiters
for indented code? Does it follow from Whitesmiths style indentation?
Is it perhaps a case of people being unaware that good editors can
properly handle auto-indentation for Ruby? Is it actually an emerging
preference in Ruby culture? I’m curious about why I see this more and
more often lately (though still notably less often, especially among
experienced coders, than the style with “end” keywords at the same
indentation level as whatever started the indented block of code – at
the same indentation level as the “def” keyword, in this case).

On May 12, 2011, at 13:51 , Chad P. wrote:

I’ve been seeing a lot of this lately:

def foo(bar)
puts bar
end

Find them.
Stab them.

On Thu, May 12, 2011 at 4:56 PM, Ryan D.
[email protected]wrote:

Stab them.

+1 on that remark! :stuck_out_tongue:
hex

I find this indenting gets best results, and more groupies.

def
foo
(bar)
puts
bar
end

I’ve never seen this even once except when it was a mistake, but maybe
it’s just me. Are you seeing this usage in prominent Ruby
frameworks/libraries (e.g. Rails, Sinatra, etc.) or Ruby code?

John F.
Principal Consultant, BitsBuilder
LI: http://www.linkedin.com/in/johnxf
SO: http://stackoverflow.com/users/75170/

On Fri, May 13, 2011 at 05:59:59AM +0900, serialhex wrote:

Stab them.

+1 on that remark! :stuck_out_tongue:

Oh, good – I’m not the only one.

On Fri, May 13, 2011 at 06:06:05AM +0900, Sam D. wrote:

I find this indenting gets best results, and more groupies.

def
foo
(bar)
puts
bar
end

That’s perverse.

On Fri, May 13, 2011 at 06:11:45AM +0900, John F. wrote:

I’ve never seen this even once except when it was a mistake, but maybe
it’s just me. Are you seeing this usage in prominent Ruby
frameworks/libraries (e.g. Rails, Sinatra, etc.) or Ruby code?

No – mostly just in code by relatively new Rubyists, such as questions
sent to this very discussion venue. People don’t tend to comment on the
formatting, though, so I was wondering if it was becoming accepted
practice. One example is the Email Parsing thread that started just
before this thread, which contains code like this:

http://codepad.org/QN7Jb6AP

It just seemed odd to me that people were answering the querents’
questions and never (apparently) batting an eye at the bizarre
indentation practices.

On Fri, May 13, 2011 at 06:53:20AM +0900, Robert K. wrote:

I don’t like it and I don’t use it either. Can’t remember though
seeing this as a trend. Maybe I’m not reading enough recent Ruby
code…

Maybe I’m just lucky.

On Thu, May 12, 2011 at 11:05 PM, Chad P. [email protected] wrote:

Find them.
Stab them.

LOL

+1 on that remark! :stuck_out_tongue:

Oh, good – I’m not the only one.

I don’t like it and I don’t use it either. Can’t remember though
seeing this as a trend. Maybe I’m not reading enough recent Ruby
code…

Cheers

robert

On Thu, May 12, 2011 at 1:51 PM, Chad P. [email protected] wrote:

 puts bar

end

Is this is “real” code (e.g., source of gems, etc.) or in snippets? If
its cut and pasted from, e.g., irb with autoindent it will look like
that.

I hope no one actually does real code that way…

On May 12, 2011, at 1:51 PM, Chad P. wrote:

I’ve been seeing a lot of this lately:

def foo(bar)
puts bar
end

Ruby 1.9.3dev emits a warning when you pull this kind of stunt:

$ ./ruby19 -v -
ruby 1.9.3dev (2011-05-13 trunk 31536) [x86_64-darwin10.7.0]
def foo(bar)
puts bar
end
-:3: warning: mismatched indentations at ‘end’ with ‘def’ at 1

On Fri, May 13, 2011 at 08:58:06AM +0900, Eric H. wrote:

ruby 1.9.3dev (2011-05-13 trunk 31536) [x86_64-darwin10.7.0]
def foo(bar)
puts bar
end
-:3: warning: mismatched indentations at ‘end’ with ‘def’ at 1

Excellent!

That is, by the way, not an error I’ve ever seen – and not one I expect
to see any time soon, either.

def foo(bar)
puts bar
end

Is this is “real” code (e.g., source of gems, etc.) or in snippets? If
its cut and pasted from, e.g., irb with autoindent it will look like
that.

Agreed. Cut n paste is a bitch that will rape your syntax. It has no
mercy. Trust it not. Opining that I’d postulate these probing
stabbings may be unwarranted.

It does look pythony though. Is that were it’s coming from?

Hang the indents!

def foo(bar)
puts bar end

MarkT

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs