# Why not adopt "Python Style" indentation for Ruby?

**URL:** <https://www.ruby-forum.com/t/why-not-adopt-python-style-indentation-for-ruby/104458>\
**Category:** Ruby\
**Created:** [May 18, 2007, 9:26am UTC](https://www.ruby-forum.com/t/why-not-adopt-python-style-indentation-for-ruby/104458 "2007-05-18T09:26:28Z")\
**Posts on this page:** 20\
**Page:** 4

<div class="post-metadata">

**Author:** ![chrisdwan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/7feea3/32.png) [@chrisdwan](https://www.ruby-forum.com/u/chrisdwan)\
**Post date:** [May 20, 2007, 7:27pm UTC](https://www.ruby-forum.com/t/why-not-adopt-python-style-indentation-for-ruby/104458/61 "2007-05-20T19:27:54Z")

</div>

I can think of an argument for making a parser simpler at the expense of  
programmer convenience, and that’s the maintainability and portability  
of  
the implementation. Some weighing of costs seems to be necessary here -  
for  
example, by hacking that extra programmer convenience syntax into the  
language, you might lose the ability to represent the language grammar  
simply and portably. Implementing a parser for Ruby, for example, is  
difficult, because there’s no grammar that you can just plug right into  
a  
parser and lexer generator. I’ve read accounts by people attempting to  
implement Ruby interpreters where parsing seems to have been a major  
stumbling block. There could be situations where that extra syntax might  
just not be worth it.

Mushfeq.

---

<div class="post-metadata">

**Author:** ![chrisdwan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/7feea3/32.png) [@chrisdwan](https://www.ruby-forum.com/u/chrisdwan)\
**Post date:** [May 20, 2007, 5:03pm UTC](https://www.ruby-forum.com/t/why-not-adopt-python-style-indentation-for-ruby/104458/62 "2007-05-20T17:03:55Z")

</div>

On 5/20/07, removed\_email\_address@domain.invalid [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I can think of three examples right off the top of my head: Rails, Rake and  
> RSpec. There’s something really eerie about seeing code like that. You _know_  
> it works, but you can’t figure out why or how.

None of those are especially magical if you have a decent understand  
of how Ruby works.  
method\_missing + block syntax does not necessary mean evil black magic.

---

<div class="post-metadata">

**Author:** ![chrisdwan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/7feea3/32.png) [@chrisdwan](https://www.ruby-forum.com/u/chrisdwan)\
**Post date:** [May 20, 2007, 8:25pm UTC](https://www.ruby-forum.com/t/why-not-adopt-python-style-indentation-for-ruby/104458/63 "2007-05-20T20:25:04Z")

</div>

On Sun, May 20, 2007 at 09:43:15PM +0900, Michael F. wrote:

> Let’s try:
> 
> describe ‘myself’  
> it ‘should be readable’  
> lambda  
> @reader.reading  
> .should change  
> @reader.knowledge  
> .by(text.amount)

If Ruby looked like that, I’d probably not have bothered – just stuck  
with Perl.

---

<div class="post-metadata">

**Author:** ![chrisdwan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/7feea3/32.png) [@chrisdwan](https://www.ruby-forum.com/u/chrisdwan)\
**Post date:** [May 20, 2007, 8:08pm UTC](https://www.ruby-forum.com/t/why-not-adopt-python-style-indentation-for-ruby/104458/64 "2007-05-20T20:08:35Z")

</div>

“tabs can be made forbidden (g.v.rossum himself said he’d never  
supported tabs in the first place if he new what it would cauze)”

Just a bit offtopic: I personally used tabs a lot and told people  
that they could adjust them to their space-likings (2 or 4), however  
as I comment quite a lot, i did find myself mixing tabs and spaces  
so I finally changed, avoid using tabs, and use 2 spaces now  
everywhere for code. (2 spaces because i like to keep 80 chars /  
line, so i can fit more into a line 🙂 )

---

<div class="post-metadata">

**Author:** ![chrisdwan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/7feea3/32.png) [@chrisdwan](https://www.ruby-forum.com/u/chrisdwan)\
**Post date:** [May 20, 2007, 9:01pm UTC](https://www.ruby-forum.com/t/why-not-adopt-python-style-indentation-for-ruby/104458/65 "2007-05-20T21:01:08Z")

</div>

On Mon, May 21, 2007 at 03:53:47AM +0900, Trans wrote:

> ```
> .by(text.amount)
> 
> ```
> 
> Though any such indention significance is probably too big of a change  
> for Ruby at this point anyway. I’d much rather just see more  
> intelligent was to catch missing “end” errors. Even if meant the  
> option to put “endif”, “endclass”, etc.

I’d prefer we keep the plain ol’ “end” syntax, and use editors that can  
do delimiter matching as easily with “end” as with braces, brackets, or  
parentheses.

---

<div class="post-metadata">

**Author:** ![chrisdwan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/7feea3/32.png) [@chrisdwan](https://www.ruby-forum.com/u/chrisdwan)\
**Post date:** [May 20, 2007, 8:54pm UTC](https://www.ruby-forum.com/t/why-not-adopt-python-style-indentation-for-ruby/104458/66 "2007-05-20T20:54:08Z")

</div>

On May 20, 8:43 am, “Michael F.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > > RSpec. There’s something really eerie about seeing code like that. You _know_  
> > > lambda  
> > > lambda{ @reader.reading }.  
> > > should change{ @reader.knowledge }.  
> > > by(text.amount)  
> > > end  
> > > end

(I take it you meant ‘if’ not ‘it’)

> # well?

Actually, the later is pretty dang ugly --maybe worse the the first.  
However colons would help the first example quite a bit:

describe ‘myself’:  
if ‘should be readable’:  
lambda:  
@reader.reading  
.should change:  
@reader.knowledge  
.by(text.amount)

Though any such indention significance is probably too big of a change  
for Ruby at this point anyway. I’d much rather just see more  
intelligent was to catch missing “end” errors. Even if meant the  
option to put “endif”, “endclass”, etc.

T.

T.

---

<div class="post-metadata">

**Author:** ![chrisdwan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/7feea3/32.png) [@chrisdwan](https://www.ruby-forum.com/u/chrisdwan)\
**Post date:** [May 20, 2007, 9:24pm UTC](https://www.ruby-forum.com/t/why-not-adopt-python-style-indentation-for-ruby/104458/67 "2007-05-20T21:24:12Z")

</div>

On May 20, 3:00 pm, Chad P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > ```
> > @reader.knowledge
> > .by(text.amount)
> > 
> > ```
> 
> > Though any such indention significance is probably too big of a change  
> > for Ruby at this point anyway. I’d much rather just see more  
> > intelligent was to catch missing “end” errors. Even if meant the  
> > option to put “endif”, “endclass”, etc.
> 
> I’d prefer we keep the plain ol’ “end” syntax, and use editors that can  
> do delimiter matching as easily with “end” as with braces, brackets, or  
> parentheses.

Yes, that would be nice, but I’ve yet to see an editor do it.

T.

---

<div class="post-metadata">

**Author:** ![chrisdwan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/7feea3/32.png) [@chrisdwan](https://www.ruby-forum.com/u/chrisdwan)\
**Post date:** [May 21, 2007, 4:29am UTC](https://www.ruby-forum.com/t/why-not-adopt-python-style-indentation-for-ruby/104458/68 "2007-05-21T04:29:02Z")

</div>

I agree that I would like the end statements to become more specific -  
at least optionally… I hate when you have a long class file and you  
get the dreaded Unexpected end of file, expecting END or something…  
and you have no idea where in the 200 lines you forgot to insert an end,  
or you left a brace hanging on the line above an end or what not. Even  
if we didn’t mandate endif, we could let end do what it does, but with  
an optional argument (end if, end class, end def) - I would use these,  
and the interpreter would thus be able to catch the error a lot closer  
to the source – class not closed at line 50 is more helpful then end of  
file at line 230…

Stian

---

<div class="post-metadata">

**Author:** ![chrisdwan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/7feea3/32.png) [@chrisdwan](https://www.ruby-forum.com/u/chrisdwan)\
**Post date:** [May 21, 2007, 1:35am UTC](https://www.ruby-forum.com/t/why-not-adopt-python-style-indentation-for-ruby/104458/69 "2007-05-21T01:35:35Z")

</div>

On Sun, 20 May 2007 09:43:00 +0200, Robert K.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) said:

> On 19.05.2007 20:48, M. Edward (Ed) Borasky wrote:

> > I don’t like to make the reader or parser work any harder than  
> > necessary just for the convenience of the coder.

> I would understand why you would want to make the reader’s job easier
> 
> - but the parser? That’s just a piece of software and I believe  
> that we should always strive to make software easier to use for  
> humans not machines.

In general, I agree. But I don’t want to ignore parsers completely -  
the easier a language is to parse, the easier it is for people to  
develop tools to work with the language, making programmers’ lives  
easier. I’m pretty sure that one of the reasons why there aren’t many  
C++ refactoring tools is because the language is incredibly difficult  
to parse, for example.

David C.  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![chrisdwan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/7feea3/32.png) [@chrisdwan](https://www.ruby-forum.com/u/chrisdwan)\
**Post date:** [May 21, 2007, 5:51am UTC](https://www.ruby-forum.com/t/why-not-adopt-python-style-indentation-for-ruby/104458/70 "2007-05-21T05:51:02Z")

</div>

On May 18, 3:50 pm, “Austin Z.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > am aware knows how to match indentation yet or do/end contexts (not  
> > that it could not be coded, thou).
> 
> Vim does this just fine.

Really? Not the vim I’m using (cream). It matches parentheses/  
brackets like most editors, but it does nothing to hilight matching do/  
end or def/end blocks. Its status line also tells me nothing about  
what function or class I’m in either. Worse, if I close a bracket,  
and the opening of it is outside the “page”, it does not tell me what  
the opening statement was. So… no, I’d say it definitively fails  
and is worse than emacs.  
Or perhaps there’s a setting I missed?

---

<div class="post-metadata">

**Author:** ![chrisdwan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/7feea3/32.png) [@chrisdwan](https://www.ruby-forum.com/u/chrisdwan)\
**Post date:** [May 21, 2007, 3:12pm UTC](https://www.ruby-forum.com/t/why-not-adopt-python-style-indentation-for-ruby/104458/71 "2007-05-21T15:12:57Z")

</div>

On 5/20/07, gga [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Really? Not the vim I’m using (cream). It matches parentheses/  
> brackets like most editors, but it does nothing to hilight matching do/  
> end or def/end blocks. Its status line also tells me nothing about  
> what function or class I’m in either. Worse, if I close a bracket,  
> and the opening of it is outside the “page”, it does not tell me what  
> the opening statement was. So… no, I’d say it definitively fails  
> and is worse than emacs.  
> Or perhaps there’s a setting I missed?

It’s probably that Cream does not have the proper ruby configuration  
files bundled with it.  
Consider using plain vim or gvim rather than Cream, as it gets rid of  
most of the reasons you’d use vim!

---

<div class="post-metadata">

**Author:** ![chrisdwan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/7feea3/32.png) [@chrisdwan](https://www.ruby-forum.com/u/chrisdwan)\
**Post date:** [May 21, 2007, 6:36pm UTC](https://www.ruby-forum.com/t/why-not-adopt-python-style-indentation-for-ruby/104458/72 "2007-05-21T18:36:32Z")

</div>

On May 21, 9:12 am, “Gregory B.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> It’s probably that Cream does not have the proper ruby configuration  
> files bundled with it.  
> Consider using plain vim or gvim rather than Cream, as it gets rid of  
> most of the reasons you’d use vim!

Someone wrote a macro (or whatever it is called) for gvim that  
automatically inserts an “end” statement whenever you enter a keyword  
that requires an “end”.

for example:  
type:

“if cond” and press return

the cursor goes to the next line and an “end” statement appears on the  
subsequent line with the proper indentation.

if cond  
# cursor at start of this line.  
end

---

<div class="post-metadata">

**Author:** ![chrisdwan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/7feea3/32.png) [@chrisdwan](https://www.ruby-forum.com/u/chrisdwan)\
**Post date:** [May 22, 2007, 4:48pm UTC](https://www.ruby-forum.com/t/why-not-adopt-python-style-indentation-for-ruby/104458/73 "2007-05-22T16:48:39Z")

</div>

On Monday, May 21 2007, Austin Z. wrote:

> I have TextMate (but don’t use it), and I’m pretty sure it can do the  
> same. I’ve heard good things about Kate from Linux users, too.

Indeed, Kate is great (although not as good as what I’veseen/heard about  
Textmate) butit certainly doesn’t highlight do…end combinations, only  
the  
standard [], {}, etc. It may be possible to add support for it,  
however.

-Ben

---

<div class="post-metadata">

**Author:** ![chrisdwan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/7feea3/32.png) [@chrisdwan](https://www.ruby-forum.com/u/chrisdwan)\
**Post date:** [June 1, 2007, 8:01am UTC](https://www.ruby-forum.com/t/why-not-adopt-python-style-indentation-for-ruby/104458/74 "2007-06-01T08:01:55Z")

</div>

On 2007-05-20 20:45:59 -0700, gga [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) said:

> > > types. And most editors can easily find matching braces. No editor I  
> > > and the opening of it is outside the “page”, it does not tell me what  
> > > the opening statement was. So… no, I’d say it definitively fails  
> > > and is worse than emacs.  
> > > Or perhaps there’s a setting I missed?

% works, but I’m using a ruby-matchit plugin I found on [vim.org](http://vim.org). I’m  
not sure if this is the same as the dist that a few guys have been  
working on at rubyforge.

---

<div class="post-metadata">

**Author:** ![chrisdwan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/7feea3/32.png) [@chrisdwan](https://www.ruby-forum.com/u/chrisdwan)\
**Post date:** [May 22, 2007, 12:22am UTC](https://www.ruby-forum.com/t/why-not-adopt-python-style-indentation-for-ruby/104458/75 "2007-05-22T00:22:32Z")

</div>

On 5/20/07, gga [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > > am aware knows how to match indentation yet or do/end contexts (not  
> > > that it could not be coded, thou).  
> > > Vim does this just fine.  
> > > Really? Not the vim I’m using (cream). It matches parentheses/  
> > > brackets like most editors, but it does nothing to hilight matching do/  
> > > end or def/end blocks. Its status line also tells me nothing about  
> > > what function or class I’m in either. Worse, if I close a bracket,  
> > > and the opening of it is outside the “page”, it does not tell me what  
> > > the opening statement was. So… no, I’d say it definitively fails  
> > > and is worse than emacs.

> Or perhaps there’s a setting I missed?

I don’t use the cream settings. I use vim with the Ruby settings  
available on RubyForge. Now, automatic highlighting isn’t present  
(e.g., the same way you get with {}), but you _can_ hit “%” to jump  
between matching pairs. It isn’t for everyone, either, but the folding  
available with vim does more for me being certain of matched pairs  
than anything else (if it doesn’t fold properly, it isn’t likely to  
compile properly).

I have TextMate (but don’t use it), and I’m pretty sure it can do the  
same. I’ve heard good things about Kate from Linux users, too.

-austin

---

<div class="post-metadata">

**Author:** ![chrisdwan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/7feea3/32.png) [@chrisdwan](https://www.ruby-forum.com/u/chrisdwan)\
**Post date:** [June 1, 2007, 10:36pm UTC](https://www.ruby-forum.com/t/why-not-adopt-python-style-indentation-for-ruby/104458/76 "2007-06-01T22:36:12Z")

</div>

On 6/1/07, Rick DeNatale [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > % works, but I’m using a ruby-matchit plugin I found on [vim.org](http://vim.org). I’m  
> > not sure if this is the same as the dist that a few guys have been  
> > working on at rubyforge.
> 
> % in vim does something related to what he’s asking for, but it  
> doesn’t automatically highlight the matching token when the cursor  
> lands on it’s mate. G?Vim will do this for single character matching  
> tokens like ( ), [] and {}, as you move the cursor over one of these  
> it will highlight its mate if it doesn’t have to scroll to do so.

Actually, mate-highlighting was added in vim 7:  
[http://vimdoc.sourceforge.net/htmldoc/pi\_paren.html#matchparen](http://vimdoc.sourceforge.net/htmldoc/pi_paren.html#matchparen)

HTH,  
Keith

---

<div class="post-metadata">

**Author:** ![chrisdwan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/7feea3/32.png) [@chrisdwan](https://www.ruby-forum.com/u/chrisdwan)\
**Post date:** [June 1, 2007, 10:07pm UTC](https://www.ruby-forum.com/t/why-not-adopt-python-style-indentation-for-ruby/104458/77 "2007-06-01T22:07:04Z")

</div>

On 6/1/07, Erik H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> On 2007-05-20 20:45:59 -0700, gga [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) said:

> > Really? Not the vim I’m using (cream). It matches parentheses/  
> > brackets like most editors, but it does nothing to hilight matching do/  
> > end or def/end blocks.

> % works, but I’m using a ruby-matchit plugin I found on [vim.org](http://vim.org). I’m  
> not sure if this is the same as the dist that a few guys have been  
> working on at rubyforge.

% in vim does something related to what he’s asking for, but it  
doesn’t automatically highlight the matching token when the cursor  
lands on it’s mate. G?Vim will do this for single character matching  
tokens like ( ), [] and {}, as you move the cursor over one of these  
it will highlight its mate if it doesn’t have to scroll to do so.

Personally, I don’t miss it much.

–  
Rick DeNatale

My blog on Ruby  
[http://talklikeaduck.denhaven2.com/](http://talklikeaduck.denhaven2.com/)

---

<div class="post-metadata">

**Author:** ![chrisdwan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/7feea3/32.png) [@chrisdwan](https://www.ruby-forum.com/u/chrisdwan)\
**Post date:** [June 2, 2007, 8:22pm UTC](https://www.ruby-forum.com/t/why-not-adopt-python-style-indentation-for-ruby/104458/78 "2007-06-02T20:22:27Z")

</div>

If you install the Vim/Ruby ([http://vim-ruby.rubyforge.org/](http://vim-ruby.rubyforge.org/)) plugins  
it’ll work with % and do/end.

Also, if you

:set sm

it will highlight briefly the opening of a block by the cursor going  
there and back really quickly AND setting the opening and closing  
markers in a different color.

There are some options with sm (showmatch) that I don’t recall. Do

:help showmatch

in Vim for details.

My experience with Vim is that if you can think of ANYTHING for Vim to  
do, chances are someone thought of it and created a plugin for it  
(yes, you can play tetris and sokoban with vim →   
([search results : vim online](http://www.vim.org/scripts/script_search_results.php?keywords=tetris&script_type=&order_by=rating&direction=descending&search=search)).

If you haven’t, I’d suggest checking the scripts section in [vim.org](http://vim.org)  
([scripts : vim online](http://www.vim.org/scripts/index.php)). Also, use the search  
([search : vim online](http://www.vim.org/search.php)) to look for plugins.

HTH

Jerry.

---

<div class="post-metadata">

**Author:** ![chrisdwan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/7feea3/32.png) [@chrisdwan](https://www.ruby-forum.com/u/chrisdwan)\
**Post date:** [June 16, 2007, 6:19am UTC](https://www.ruby-forum.com/t/why-not-adopt-python-style-indentation-for-ruby/104458/79 "2007-06-16T06:19:41Z")

</div>

I love indentations too…

Check out my project for Ruby space convention 😕

[http://lazibi.rubyforge.org](http://lazibi.rubyforge.org)

It’s code generation.

---

<div class="post-metadata">

**Author:** ![chrisdwan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/7feea3/32.png) [@chrisdwan](https://www.ruby-forum.com/u/chrisdwan)\
**Post date:** [September 25, 2007, 11:07pm UTC](https://www.ruby-forum.com/t/why-not-adopt-python-style-indentation-for-ruby/104458/80 "2007-09-25T23:07:17Z")

</div>

> Jinjing Wang wrote:  
> I love indentations too…
> 
> Check out my project for Ruby space convention 😕
> 
> [http://lazibi.rubyforge.org](http://lazibi.rubyforge.org)
> 
> It’s code generation.

You don’t need to do code generation, at least in the way you have done  
it. I posted a solution way back up this thread that does not require  
the creation of intermediate files to load.

In foo.rb

require ‘pyrb.rb’  
**END**

def foo:  
[1,2,3,4].each do |i|:  
puts i  
[1,2,3,4].each do |j|:  
puts i  
if i == 2 :  
puts “foo”  
else:  
puts “bar”

foo

See

[http://xtargets.com/snippets/posts/show/68](http://xtargets.com/snippets/posts/show/68)

for the details.

[Previous page](https://www.ruby-forum.com/t/why-not-adopt-python-style-indentation-for-ruby/104458.md?page=3)

[Next page](https://www.ruby-forum.com/t/why-not-adopt-python-style-indentation-for-ruby/104458.md?page=5)
