# 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:** 2

<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 18, 2007, 6:05pm UTC](https://www.ruby-forum.com/t/why-not-adopt-python-style-indentation-for-ruby/104458/21 "2007-05-18T18:05:46Z")

</div>

Dnia Sat, 19 May 2007 00:26:15 +0900, Gregory B. napisa³(a):

> Except eRuby is a general templating system, and Haml is for XHTML generation.

It is not true. Haml can generate non valid XML content as well. But it  
is  
true that Haml main target is XHTML and CSS generation. For CSS  
generation  
is Sass which uses very similiar approach  
[http://haml.hamptoncatlin.com/docs/sass](http://haml.hamptoncatlin.com/docs/sass)

Is it not strange that such solution was invented  
by Ruby, not Python, guys? 🙂

---

<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 18, 2007, 5:44pm UTC](https://www.ruby-forum.com/t/why-not-adopt-python-style-indentation-for-ruby/104458/22 "2007-05-18T17:44:42Z")

</div>

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

> 

He didn’t say anything about readability. In terms of syntax structure  
and  
consistency, Haskell _is_ better than Python. Every language is easy to  
read  
if you’re used to reading it.

Jason

---

<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 18, 2007, 6:17pm UTC](https://www.ruby-forum.com/t/why-not-adopt-python-style-indentation-for-ruby/104458/23 "2007-05-18T18:17:47Z")

</div>

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

> > - templates, e.g. eRuby  
> > eRuby is crap if you compare it with Haml template  
> > [http://haml.hamptoncatlin.com/](http://haml.hamptoncatlin.com/).

How well does Haml work with non-HTML templating?

-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:** [May 18, 2007, 6:18pm UTC](https://www.ruby-forum.com/t/why-not-adopt-python-style-indentation-for-ruby/104458/24 "2007-05-18T18:18:47Z")

</div>

Hi,

In message “Re: Why not adopt “Python Style” indentation for Ruby?”  
on Sat, 19 May 2007 00:20:06 +0900, Jaroslaw Z.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) writes:

|\> I admit Haskell syntax is much better than Python’s.  
|  
|Matz, you must be joking… Python is much easier to read than Haskell.

To rephrase, “Haskell INDENTATION SYNTAX is much better than  
Python’s”. Clear?

```
          matz.

```

---

<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 18, 2007, 6:22pm UTC](https://www.ruby-forum.com/t/why-not-adopt-python-style-indentation-for-ruby/104458/25 "2007-05-18T18:22:50Z")

</div>

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

> Dnia Sat, 19 May 2007 00:26:15 +0900, Gregory B. napisa³(a):
> 
> > Except eRuby is a general templating system, and Haml is for XHTML generation.  
> > It is not true. Haml can generate non valid XML content as well. But it is  
> > true that Haml main target is XHTML and CSS generation. For CSS generation  
> > is Sass which uses very similiar approach  
> > [http://haml.hamptoncatlin.com/docs/sass](http://haml.hamptoncatlin.com/docs/sass)

Neither is useful for those of us who want general purpose templating.

There are bigger problems in the world than your little web-apps.

-austin, generates C++ with erb

---

<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 18, 2007, 6:26pm UTC](https://www.ruby-forum.com/t/why-not-adopt-python-style-indentation-for-ruby/104458/26 "2007-05-18T18:26:51Z")

</div>

Hi,

In message “Re: Why not adopt “Python Style” indentation for Ruby?”  
on Sat, 19 May 2007 00:15:05 +0900, Jaroslaw Z.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) writes:

|What do you think about OPTIONAL block indendation in Ruby?

I am not positive for general block-by-indentation idea. If one  
REALLY loves the idea, Python always waits for you.

But I sometime want “end”-less single line structure (in normal  
order), e.g.

if foo then bar # pseudo syntax; you may require delimiters

not

bar if foo

especially when I write very small code chunk. Not knowing what  
syntax it should be.

```
          matz.

```

---

<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 18, 2007, 6:20pm UTC](https://www.ruby-forum.com/t/why-not-adopt-python-style-indentation-for-ruby/104458/27 "2007-05-18T18:20:50Z")

</div>

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

> On 5/18/07, Yukihiro M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:  
> I’ve picked up on python in the last couple months and like the  
> indentation. In addition to forced readablity, I find another  
> practical benefit is that it eliminates hard to track down syntax  
> errors due to matching {}, begin/end, etc. In ruby, C, perl, etc  
> these errors can be painful to track down in a large file with lots of  
> blocks within blocks.

Scope indicated by whitespace is an indication, IMO, that the compiler  
thinks that it knows better than you do.

Always a mistake.

I want a programming language that works how I do; I don’t want to  
have to work how a stupid programming language requires it.

(I sometimes put debug statements flush left so that it’s a simple  
/^p to search for them. Can’t do that with scope controlled by  
whitespace. Dumb, dumb, dumb, dumb.)

-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:** [May 18, 2007, 6:59pm UTC](https://www.ruby-forum.com/t/why-not-adopt-python-style-indentation-for-ruby/104458/28 "2007-05-18T18:59:52Z")

</div>

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

> thinks that it knows better than you do.
> 
> Always a mistake.
> 
> I want a programming language that works how I do; I don’t want to  
> have to work how a stupid programming language requires it.
> 
> (I sometimes put debug statements flush left so that it’s a simple  
> /^p to search for them. Can’t do that with scope controlled by  
> whitespace. Dumb, dumb, dumb, dumb.)

That is the exact same case I find the indentation thing gets in the  
way. I had to change my way of putting in print debug statements  
(same as yours). Every language makes you change your ways a bit. Of  
course python’s debug facilities (pdb) are much better than ruby’s so  
I don’t do print debugging as much.

I would rather have multiple ways to specify blocks:

- {}'s
- indentation
- in-line (single statement/expression)

BTW, python’s lambda sucks! You can’t put generic code in there - it  
must be a single expression. I think it has to do with the  
indentation thing. Only statements can have code blocks (using  
indentation) and a lambda is an expression. I don’t like the clear  
separation of statements and expressions that python has. I think it  
all comes back to the indentation thing. They didn’t do it right.  
Sounds like Haskell did (but I have no experience with it).

---

<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 18, 2007, 6:26pm UTC](https://www.ruby-forum.com/t/why-not-adopt-python-style-indentation-for-ruby/104458/29 "2007-05-18T18:26:51Z")

</div>

In message  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid), “Austin  
Ziegler” writ  
es:

> (I sometimes put debug statements flush left so that it’s a simple  
> /^p to search for them. Can’t do that with scope controlled by  
> whitespace. Dumb, dumb, dumb, dumb.)

Suspiciously familiar!

-s

---

<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 18, 2007, 7:45pm UTC](https://www.ruby-forum.com/t/why-not-adopt-python-style-indentation-for-ruby/104458/30 "2007-05-18T19:45:59Z")

</div>

On 2007-05-18, gga [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> No editor I am aware knows how to match indentation yet or do/end  
> contexts (not that it could not be coded, thou).

Emacs + ruby-mode.el understands do/end just fine.

Regards,

Jeremy H.

---

<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 18, 2007, 8:13pm UTC](https://www.ruby-forum.com/t/why-not-adopt-python-style-indentation-for-ruby/104458/31 "2007-05-18T20:13:02Z")

</div>

Chris D. wrote:

> As far as I can see, the ‘end’ keyword is ‘repeating yourself’ when  
> used with properly indented code.
> 
> class Foo
> 
> def bar(value)  
> if value \< 7  
> puts “hello”  
> else  
> puts “world”  
> end  
> end
> 
> def foobar  
> puts “foobar”  
> end
> 
> end
> 
> could be
> 
> class Foo
> 
> def bar(value)  
> if value \< 7  
> puts “hello”  
> else  
> puts “world”
> 
> def foobar  
> puts “foobar”

The is one big disadvantage in Python’s syntax. Things like…

def bar(value); (value\<7) ? (puts “hello”) : (puts “world”); end

…are not possible in Python - and they are useful for the typical  
one-to-three-liners in support areas, where Ruby still has the chance to  
replace Perl - a chance that Python never had.

I know that my example has nothing to do with documentation oriented  
software development, but this is not necessary for a broad range of  
small ad-hoc tools.

Wolfgang NÃ¡dasi-Donner

---

<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 18, 2007, 7:25pm UTC](https://www.ruby-forum.com/t/why-not-adopt-python-style-indentation-for-ruby/104458/32 "2007-05-18T19:25:55Z")

</div>

On May 18, 12:19 pm, “Eric M.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> blocks within blocks.  
> No, it is just the other way around. Languages that use curly braces  
> for indentation like C, Perl, etc. are EASY to work with once code is  
> not properly factored and it extends outside a single page. Ruby is  
> easy only when you use {, not so much when you use do/end,  
> unfortunately, as most editors know nothing about it. Some good  
> editors (emacs, for example), can tell you the context you are in the  
> modeline with curly braces, but not so with other block indentation  
> types. And most editors can easily find matching braces. No editor I  
> am aware knows how to match indentation yet or do/end contexts (not  
> that it could not be coded, thou).

Python is a true nightmare to debug and understand once you have code  
that trails off a single page. A good example of these problems, for  
example, is the Maya Python API which is as ugly as it can be, using  
all of the ugliest things of python (tabulation using tabs, lots of  
underscore methods, lots of code that is not easily refactored, etc).

Another problem with indentation only that has not been mentioned is  
that simple cut and paste of source code between two files is not  
guaranteed to work (and often will lead to a syntax error or worse, a  
runtime error). This to me is still a big no-no for indentation only,  
as most programmers _do_ often cut and paste code from different  
contexts or files. With languages that use braces or Ruby’s do/end  
you really don’t have to worry about that, for the most part.

---

<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 18, 2007, 8:20pm UTC](https://www.ruby-forum.com/t/why-not-adopt-python-style-indentation-for-ruby/104458/33 "2007-05-18T20:20:05Z")

</div>

> _language_ features where Python leads Ruby.)  
> Here my 5 cents…

Gentlemen, if you want to code Python style, go ahead, program in  
Python.

I mean every language has it’s pros an cons. I come from a Java world  
(11 years of Java) and I am not asking that Ruby should be Java like.  
That is absolute nonsense.

Ruby is like Ruby, so, if you like it (as I do) take it, if you  
don’t… there are lots of different programming languages out there  
you can choose from, or like Mats, go ahead and develop your own (you  
will notice it’s actually not that easy to do it right…)

Cheers,

Enrique Comba R.

---

<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 18, 2007, 8:17pm UTC](https://www.ruby-forum.com/t/why-not-adopt-python-style-indentation-for-ruby/104458/34 "2007-05-18T20:17:02Z")

</div>

“Yukihiro M.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote in message  
news:removed\_email\_address@domain.invalid…

> Hi,
> 
> In message “Re: Why not adopt “Python Style” indentation for Ruby?”  
> on Fri, 18 May 2007 23:15:05 +0900, “S.Volkov” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> writes:

…

> |suggestion: make ‘end’ optional if code block contains only one  
> statement;
> 
> I’m not sure if we can define syntax for above suggestion.
> 
> while cond  
> puts a  
> puts b # delimit by indentation or else??  
> You are right, not feasible - rejected 🙂

> or maybe
> 
> while cond: puts a # should be in same line  
> Thus we introduce new semantic for newline!  
> Following construct becomes invalid (and confusing):  
> while cond: puts a  
> puts b  
> end  
> =\>my personal opinion - NO

imho: we need special terminator anyway, now it is ‘end’, could be  
another;  
suggestion: introduce ‘;;’ terminator for 'implicit blocks (not started  
with  
class/module/def/do/begin), ie:  
#–  
while cond : puts a ; puts b ;;  
# but  
while cond do puts a ; puts b end  
#-- until - same as while  
#–  
if cond : p a ;;  
#–  
if cond : p a else p b ;;  
#-- unless - same as if  
#–  
for var in expr : p var ;;  
# but  
for var in expr do p var end  
#-- case - sorry my lunch time ended, has to return back to my office…

BRs  
Sergey V.

---

<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 18, 2007, 8:21pm UTC](https://www.ruby-forum.com/t/why-not-adopt-python-style-indentation-for-ruby/104458/35 "2007-05-18T20:21:05Z")

</div>

Hi,

In message “Re: Why not adopt “Python Style” indentation for Ruby?”  
on Sat, 19 May 2007 03:15:17 +0900, “S.Volkov” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
writes:

|imho: we need special terminator anyway, now it is ‘end’, could be another;  
|suggestion: introduce ‘;;’ terminator for 'implicit blocks (not started with  
|class/module/def/do/begin), ie:

For your information, 1.9 once had exact same syntax you’ve proposed  
for a short while. I have a time machine. The idea was abandoned  
since it caused serious unreadability.

```
          matz.

```

---

<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 18, 2007, 11:18pm UTC](https://www.ruby-forum.com/t/why-not-adopt-python-style-indentation-for-ruby/104458/36 "2007-05-18T23:18:25Z")

</div>

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

> with  
> |class/module/def/do/begin), ie:
> 
> For your information, 1.9 once had exact same syntax you’ve proposed  
> for a short while. I have a time machine. The idea was abandoned  
> since it caused serious unreadability.
> 
> ```
> matz.
> 
> ```

Very glad to hear it. We don’t want Ruby turning into Ocaml, rife with  
unreadable symbols and impossible to follow constructions.

Ruby’s do/end is just fine. So we can’t do two-liner if statements. I’ve  
never, ever liked that syntax as it makes code at first glance  
confusing.  
e.g.:

int i = 0, j = 0, x = 0;  
for(i = 0; i \< 10 ; i++)  
for(j = 0; j \< 30; j++);  
for(x = 0; x \< 100; x++)  
printf(i + j + x);

I’m a big fan of the more verbose keywords of Ruby because for one there  
are  
very few of them and two it makes the language easy to read.

Jason

---

<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 18, 2007, 8:51pm UTC](https://www.ruby-forum.com/t/why-not-adopt-python-style-indentation-for-ruby/104458/37 "2007-05-18T20:51:07Z")

</div>

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

> No, it is just the other way around. Languages that use curly braces  
> for indentation like C, Perl, etc. are EASY to work with once code is  
> not properly factored and it extends outside a single page. Ruby is  
> easy only when you use {, not so much when you use do/end,  
> unfortunately, as most editors know nothing about it. Some good  
> editors (emacs, for example), can tell you the context you are in the  
> modeline with curly braces, but not so with other block indentation  
> types. And most editors can easily find matching braces. No editor I  
> 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.

-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:** [May 18, 2007, 11:23pm UTC](https://www.ruby-forum.com/t/why-not-adopt-python-style-indentation-for-ruby/104458/38 "2007-05-18T23:23:26Z")

</div>

Eric M. schrieb:

> You might consider something like this as an alternative block syntax.  
> Maybe a “:” followed by a newline (and extra indentation) would start  
> this style. I’m not sure of a clean way to handle arguments though.

What about another syntax:  
Putting a special character at the beginning of every line that is  
governed by significant whitespace.  
Thes would cause no problems with normal Ruby syntax,  
but would provide a way to use significant indentation if one really  
wants to.

If “~” were that special character, it would look like that:  
~ 5.times do |n|  
~ n.times do  
~ print n  
~ puts

Of course, hardly any editor would be prepared to support this,  
currently…

This approach would have the additional advantage  
of being more robust to contexts where leading whitespace  
gets stripped.

Cheers  
Sven

---

<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 19, 2007, 12:42am UTC](https://www.ruby-forum.com/t/why-not-adopt-python-style-indentation-for-ruby/104458/39 "2007-05-19T00:42:34Z")

</div>

On May 18, 5:22 pm, Sven S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> but would provide a way to use significant indentation if one really  
> wants to.
> 
> If “~” were that special character, it would look like that:  
> ~ 5.times do |n|  
> ~ n.times do  
> ~ print n  
> ~ puts

I can’t count how many times I’ve forgotten “do”. Sometimes I have  
wished a colon could “induce” the block:

5.times |n|:  
n.times:  
print n  
puts

But I don’t think a line prefix is worth the trouble.

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 18, 2007, 11:26pm UTC](https://www.ruby-forum.com/t/why-not-adopt-python-style-indentation-for-ruby/104458/40 "2007-05-18T23:26:26Z")

</div>

Yukihiro M. schrieb:

> syntax it should be.

+1

Sven

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

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