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).

···

--
Chad Perrin [ original content licensed OWL: http://owl.apotheon.org ]

Find them.
Stab them.

···

On May 12, 2011, at 13:51 , Chad Perrin wrote:

I've been seeing a lot of this lately:

   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 Feminella
Principal Consultant, BitsBuilder
LI: http://www.linkedin.com/in/johnxf
SO: User John Feminella - Stack Overflow

On Thu, May 12, 2011 at 16:51, Chad Perrin <code@apotheon.net> wrote:

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).

--
Chad Perrin [ original content licensed OWL: http://owl.apotheon.org ]

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 May 12, 2011, at 1:51 PM, Chad Perrin wrote:

I've been seeing a lot of this lately:

   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.

I hope no one actually does real code that way...

···

On Thu, May 12, 2011 at 1:51 PM, Chad Perrin <code@apotheon.net> wrote:

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

+1 on that remark! :stuck_out_tongue:
hex

···

On Thu, May 12, 2011 at 4:56 PM, Ryan Davis <ryand-ruby@zenspider.com>wrote:

On May 12, 2011, at 13:51 , Chad Perrin wrote:

> I've been seeing a lot of this lately:
>
> def foo(bar)
> puts bar
> end

Find them.
Stab them.

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

def\
     foo\
         (bar)
             puts\
                  bar
                     end

···

On 13/05/11 08:56, Ryan Davis wrote:

On May 12, 2011, at 13:51 , Chad Perrin wrote:

I've been seeing a lot of this lately:

    def foo(bar)
      puts bar
      end

Find them.
Stab them.

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:

    Plain Text code - 18 lines - codepad

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:11:45AM +0900, John Feminella 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?

--
Chad Perrin [ original content licensed OWL: http://owl.apotheon.org ]

> 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?

Excellent!

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

···

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

On May 12, 2011, at 1:51 PM, Chad Perrin 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

--
Chad Perrin [ original content licensed OWL: http://owl.apotheon.org ]

Oh, good -- I'm not the only one.

···

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

On Thu, May 12, 2011 at 4:56 PM, Ryan Davis <ryand-ruby@zenspider.com>wrote:
> On May 12, 2011, at 13:51 , Chad Perrin wrote:
> >
> > I've been seeing a lot of this lately:
> >
> > def foo(bar)
> > puts bar
> > end
>
> Find them.
> Stab them.

+1 on that remark! :stuck_out_tongue:

--
Chad Perrin [ original content licensed OWL: http://owl.apotheon.org ]

That's perverse.

···

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

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

def\
    foo\
        (bar)
            puts\
                 bar
                    end

--
Chad Perrin [ original content licensed OWL: http://owl.apotheon.org ]

Hang the indents!

def foo(bar)
  puts bar end

MarkT

recvfile.rb (1.89 KB)

> >
> > I've been seeing a lot of this lately:
> >
> > def foo(bar)
> > puts bar
> > end
>
> 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 11:05 PM, Chad Perrin <code@apotheon.net> wrote:

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

On Thu, May 12, 2011 at 4:56 PM, Ryan Davis <ryand-ruby@zenspider.com>wrote:
> On May 12, 2011, at 13:51 , Chad Perrin wrote:

--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

Maybe I'm just lucky.

···

On Fri, May 13, 2011 at 06:53:20AM +0900, Robert Klemme 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...

--
Chad Perrin [ original content licensed OWL: http://owl.apotheon.org ]