# Indentation vs. "end"s

**URL:** <https://www.ruby-forum.com/t/indentation-vs-end-s/99901>\
**Category:** Ruby\
**Created:** [February 1, 2006, 10:39pm UTC](https://www.ruby-forum.com/t/indentation-vs-end-s/99901 "2006-02-01T22:39:19Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![rubyist](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/bbe5ce/32.png) [@rubyist](https://www.ruby-forum.com/u/rubyist)\
**Post date:** [February 1, 2006, 10:39pm UTC](https://www.ruby-forum.com/t/indentation-vs-end-s/99901/1 "2006-02-01T22:39:19Z")

</div>

Hi,

I _REALLY_ love Ruby very much. But I always find those "end"s somewhat  
ugly ( thousands of excuses to Matz ). I sometimes feel myself wishing  
that Ruby use indentation (as Python does) instead of "end"s.

Today, I have seen a post in:

[http://www.artima.com/weblogs/viewpost.jsp?thread=146091](http://www.artima.com/weblogs/viewpost.jsp?thread=146091)

As far as I know, Bruce Eckel is a competent programmer and when I saw  
that he was agree with me, I surprised.

What do you think about those "end"s? Do you _REALLY_ like them?  
Will Ruby-2 offer an alternative? Well, maybe not “indentation” but  
will another solution be available?

---

<div class="post-metadata">

**Author:** ![rubyist](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/bbe5ce/32.png) [@rubyist](https://www.ruby-forum.com/u/rubyist)\
**Post date:** [February 1, 2006, 10:42pm UTC](https://www.ruby-forum.com/t/indentation-vs-end-s/99901/2 "2006-02-01T22:42:22Z")

</div>

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

> As far as I know, Bruce Eckel is a competent programmer and when I saw  
> that he was agree with me, I surprised.
> 
> What do you think about those "end"s? Do you _REALLY_ like them?  
> Will Ruby-2 offer an alternative? Well, maybe not “indentation” but  
> will another solution be available?

I’ve got to declare that I also like the idea of dropping the ends a la  
Python, although if the effect of that is that your whitespace becomes  
strict I’m not sure which way is better. I have looked at some of my and  
other people’s Ruby code and often been tempted to select those last 5  
‘ends’ and hit the delete button. : )

Luke

---

<div class="post-metadata">

**Author:** ![rubyist](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/bbe5ce/32.png) [@rubyist](https://www.ruby-forum.com/u/rubyist)\
**Post date:** [February 1, 2006, 10:42pm UTC](https://www.ruby-forum.com/t/indentation-vs-end-s/99901/3 "2006-02-01T22:42:22Z")

</div>

Yes I really like the end statements, and they make it easier for  
beginners. It’s possible to support both indenting and end statements  
(i.e. support one mode or the other), and you don’t need python’s  
redundant and unnecessary colons. I implemented this myself in a  
parser. I don’t think it is appropriate for ruby, however.

What would be even better would be to allow optional labels after end  
statements, such as “end class”, “end def”, so the parser can catch  
more errors.  
I’ve implemented this as well in a separate project.

---

<div class="post-metadata">

**Author:** ![rubyist](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/bbe5ce/32.png) [@rubyist](https://www.ruby-forum.com/u/rubyist)\
**Post date:** [February 1, 2006, 10:45pm UTC](https://www.ruby-forum.com/t/indentation-vs-end-s/99901/4 "2006-02-01T22:45:26Z")

</div>

In article [nUfDf.49093$removed\_email\_address@domain.invalid](mailto:nUfDf.49093$removed_email_address@domain.invalid),  
Jeffrey S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > 
> 
> block-ending tokens also help when I am skimming code to review its  
> structure.

And having ‘end’ sure makes things like ERB easier (possible) to  
implement.

Phil

---

<div class="post-metadata">

**Author:** ![rubyist](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/bbe5ce/32.png) [@rubyist](https://www.ruby-forum.com/u/rubyist)\
**Post date:** [February 1, 2006, 10:48pm UTC](https://www.ruby-forum.com/t/indentation-vs-end-s/99901/5 "2006-02-01T22:48:31Z")

</div>

> > I have looked at some of my and other people’s Ruby code and  
> > often been tempted to select those last 5  
> > ‘ends’ and hit the delete button. : )

Thank God! I am not alone on the earth! ;-D  
Man, you’ve made me so laughed! Hahaha!

---

<div class="post-metadata">

**Author:** ![rubyist](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/bbe5ce/32.png) [@rubyist](https://www.ruby-forum.com/u/rubyist)\
**Post date:** [February 1, 2006, 10:48pm UTC](https://www.ruby-forum.com/t/indentation-vs-end-s/99901/6 "2006-02-01T22:48:31Z")

</div>

> > What would be even better would be to allow optional labels after end  
> > statements, such as “end class”, “end def”, so the parser can catch  
> > more errors.

That sound like a good idea. But what about “if”, “when”, “for”,  
“until” etc?  
Hmm…  
“endif”, “end when”, “end for”, “end until”, “end class”, “enddef”,…  
Umh! A never “ended” nightmare.

---

<div class="post-metadata">

**Author:** ![rubyist](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/bbe5ce/32.png) [@rubyist](https://www.ruby-forum.com/u/rubyist)\
**Post date:** [February 1, 2006, 10:42pm UTC](https://www.ruby-forum.com/t/indentation-vs-end-s/99901/7 "2006-02-01T22:42:22Z")

</div>

Rubyist wrote:

> As far as I know, Bruce Eckel is a competent programmer and when I saw  
> that he was agree with me, I surprised.
> 
> What do you think about those "end"s? Do you _REALLY_ like them?  
> Will Ruby-2 offer an alternative? Well, maybe not “indentation” but  
> will another solution be available?

I like having something to search for in my editor. Explicit  
block-ending tokens also help when I am skimming code to review its  
structure.

---

<div class="post-metadata">

**Author:** ![rubyist](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/bbe5ce/32.png) [@rubyist](https://www.ruby-forum.com/u/rubyist)\
**Post date:** [February 1, 2006, 10:57pm UTC](https://www.ruby-forum.com/t/indentation-vs-end-s/99901/8 "2006-02-01T22:57:39Z")

</div>

-Rubyist [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> What do you think about those "end"s? Do you _REALLY_ like them?  
> Will Ruby-2 offer an alternative? Well, maybe not “indentation” but  
> will another solution be available?

You’re asking for trouble when using something like eruby.

ngw

---

<div class="post-metadata">

**Author:** ![rubyist](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/bbe5ce/32.png) [@rubyist](https://www.ruby-forum.com/u/rubyist)\
**Post date:** [February 2, 2006, 1:03am UTC](https://www.ruby-forum.com/t/indentation-vs-end-s/99901/9 "2006-02-02T01:03:13Z")

</div>

i like the "end"s, it reminds me of the old days when i programmed my  
Texas  
Instruments calculator and always forgot an “end” somewhere 😛

2006/2/1, Phil T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

---

<div class="post-metadata">

**Author:** ![rubyist](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/bbe5ce/32.png) [@rubyist](https://www.ruby-forum.com/u/rubyist)\
**Post date:** [February 1, 2006, 10:51pm UTC](https://www.ruby-forum.com/t/indentation-vs-end-s/99901/10 "2006-02-01T22:51:36Z")

</div>

Rubyist [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > What would be even better would be to allow optional labels  
> > after end statements, such as “end class”, “end def”, so the  
> > parser can catch more errors.
> 
> That sound like a good idea. But what about “if”, “when”,  
> “for”, “until” etc?  
> Hmm…  
> “endif”, “end when”, “end for”, “end until”, “end class”, “enddef”,…

Or how 'bout “if - fi” and “until - done” and “for - done”…  
nah. As much as the Bourne shell has a few constructs that  
seem to meet your criteria, I don’t think it’s the answer.

I have to say, as much as I like the idea of significant  
whitespace for _certain_ things (preservation of vertical  
space; force new programmers to indent), I just don’t think it’s  
the right solution here, either.

Besides, Python has no solution for _which_ scope is ended when  
code is reverse indented. It’s clean, but not descriptive.

I agree that Ruby’s explicit "end"s make it nicer for use in  
erb. And at least this way you can, for your posterity’s sake,  
do:

```
stuff.each do |thing|
  if thing.instance_of?(other_thing)
    thing.action()
  end # if
end # each stuff

```

Cheers,  
Tim H.

---

<div class="post-metadata">

**Author:** ![rubyist](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/bbe5ce/32.png) [@rubyist](https://www.ruby-forum.com/u/rubyist)\
**Post date:** [February 2, 2006, 1:06am UTC](https://www.ruby-forum.com/t/indentation-vs-end-s/99901/11 "2006-02-02T01:06:14Z")

</div>

On Feb 1, 2006, at 1:37 PM, Luke Duncalfe wrote:

> my and  
> other people’s Ruby code and often been tempted to select those last 5  
> ‘ends’ and hit the delete button. : )

I typically find I’m doing something wrong if I have five ends in a  
row. Too much complexity in one method. Three is usually my max,  
but I don’t make a rule of it, it just happens.

–  
Eric H. - removed\_email\_address@domain.invalid - [http://segment7.net](http://segment7.net)  
This implementation is HODEL-HASH-9600 compliant

[http://trackmap.robotcoop.com](http://trackmap.robotcoop.com)

---

<div class="post-metadata">

**Author:** ![rubyist](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/bbe5ce/32.png) [@rubyist](https://www.ruby-forum.com/u/rubyist)\
**Post date:** [February 2, 2006, 1:12am UTC](https://www.ruby-forum.com/t/indentation-vs-end-s/99901/12 "2006-02-02T01:12:19Z")

</div>

2006/2/1, Rubyist [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> Hi,
> 
> I _REALLY_ love Ruby very much. But I always find those "end"s somewhat  
> ugly ( thousands of excuses to Matz ). I sometimes feel myself wishing  
> that Ruby use indentation (as Python does) instead of "end"s.

> What do you think about those "end"s? Do you _REALLY_ like them?  
> Will Ruby-2 offer an alternative? Well, maybe not “indentation” but  
> will another solution be available?

I don’t even think about them. I just use the language as it is.

robert

---

<div class="post-metadata">

**Author:** ![rubyist](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/bbe5ce/32.png) [@rubyist](https://www.ruby-forum.com/u/rubyist)\
**Post date:** [February 2, 2006, 1:15am UTC](https://www.ruby-forum.com/t/indentation-vs-end-s/99901/13 "2006-02-02T01:15:22Z")

</div>

On 01/02/06, Rubyist [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> What do you think about those "end"s? Do you _REALLY_ like them?  
> Will Ruby-2 offer an alternative? Well, maybe not “indentation” but  
> will another solution be available?

I hope that the mistake that Python makes isn’t repeated in Ruby 2.0.

I prefer explicit – and more flexible – than implicit and  
inflexible. In other words, I really _do_ like the ends.

-austin

---

<div class="post-metadata">

**Author:** ![rubyist](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/bbe5ce/32.png) [@rubyist](https://www.ruby-forum.com/u/rubyist)\
**Post date:** [February 2, 2006, 1:42am UTC](https://www.ruby-forum.com/t/indentation-vs-end-s/99901/14 "2006-02-02T01:42:46Z")

</div>

On Feb 1, 2006, at 5:21 PM, Eric H. wrote:

> On Feb 1, 2006, at 1:37 PM, Luke Duncalfe wrote:
> 
> > “Rubyist” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote in message
> > 
> > > What do you think about those "end"s? Do you _REALLY_ like them?
> 
> I typically find I’m doing something wrong if I have five ends in a  
> row. Too much complexity in one method. Three is usually my max,  
> but I don’t make a rule of it, it just happens.

+1

Gary W.

---

<div class="post-metadata">

**Author:** ![rubyist](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/bbe5ce/32.png) [@rubyist](https://www.ruby-forum.com/u/rubyist)\
**Post date:** [February 2, 2006, 1:45am UTC](https://www.ruby-forum.com/t/indentation-vs-end-s/99901/15 "2006-02-02T01:45:50Z")

</div>

I’m pretty much a newbie programmer so my opinion shouldn’t count much  
but before I chose Ruby as the definite language I tried writing in as  
many other languages as I could, including Python.

I understand the importance of indentation, but forcing it on me was  
really painful. I honestly wanted to stab someone every time I got an  
error (ruby give me an error too when I missed an end, but it’s somehow  
different). There is something incredibly soothing about writing  
freeform and freestyle code in Ruby which I don’t get in Python.

What I’m afraid of now is going to college next year and having to deal  
with “stricter” languages.

Good Luck!  
Gabriel

PS: Yes, I know writing code cowboy style is bad, but hey, I’m a  
newbie. 😉

---

<div class="post-metadata">

**Author:** ![rubyist](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/bbe5ce/32.png) [@rubyist](https://www.ruby-forum.com/u/rubyist)\
**Post date:** [February 2, 2006, 1:21am UTC](https://www.ruby-forum.com/t/indentation-vs-end-s/99901/16 "2006-02-02T01:21:29Z")

</div>

On Wednesday 01 February 2006 22:37, removed\_email\_address@domain.invalid wrote:

> What would be even better would be to allow optional labels after end  
> statements, such as “end class”, “end def”, so the parser can catch  
> more errors.  
> I’ve implemented this as well in a separate project.

Holy mother of god in the heavens, for the love of all that’s good and  
sacred,  
please NO! I’ve had more than enough XML and VHDL already,  
thankyouverymuch.  
Next thing you see we’re coding in palindromes to doublecheck we know  
what  
order we wrote the characters in…

I want to see a single half-serious programmer that actually makes  
errors  
because he can’t remember what scope he’s in. That’s what the  
indentation  
conventions are there anyway. If you keep your code well-structured,  
It’s  
impossible to have that cause a show-stopping bug that can survive five  
minutes in the codebase.

That said, I prefer indentation as a convention, not as syntax. I made  
certain  
sporadic forays into Python; but I like how Ruby tries to resemble  
natural  
language with the likes of statement modifiers, and do/begin and end for  
code  
blocks. It feels more natural to me to type “end” to end a code block,  
and I  
usually associate the backspace key probably the most commonly used in  
editors to unindent code manually with correcting typos - ergo not a  
natural  
component in the flow of typing.

Pretty much my $.02

David V.  
If I had two cents for everytime I say “Just my two cents”…

---

<div class="post-metadata">

**Author:** ![rubyist](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/bbe5ce/32.png) [@rubyist](https://www.ruby-forum.com/u/rubyist)\
**Post date:** [February 2, 2006, 2:40am UTC](https://www.ruby-forum.com/t/indentation-vs-end-s/99901/17 "2006-02-02T02:40:17Z")

</div>

On 01/02/06, Rubyist [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > > What would be even better would be to allow optional labels after end  
> > > statements, such as “end class”, “end def”, so the parser can catch  
> > > more errors.  
> > > That sound like a good idea. But what about “if”, “when”, “for”,  
> > > “until” etc?  
> > > Hmm…  
> > > “endif”, “end when”, “end for”, “end until”, “end class”, “enddef”,…  
> > > Umh! A never “ended” nightmare.

I’m not particularly fond of IF … ENDIF constructs, but one can  
simulate this:

def foo  
…  
end # def foo

I don’t do it, though. Vim does a damn fine job of folding things for  
me.

-austin

---

<div class="post-metadata">

**Author:** ![rubyist](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/bbe5ce/32.png) [@rubyist](https://www.ruby-forum.com/u/rubyist)\
**Post date:** [February 2, 2006, 3:43am UTC](https://www.ruby-forum.com/t/indentation-vs-end-s/99901/18 "2006-02-02T03:43:35Z")

</div>

Dirk M. wrote:

> i like the "end"s, it reminds me of the old days when i programmed my Texas  
> Instruments calculator and always forgot an “end” somewhere 😛

I loved my TI-82, and I remember how excited I was over my 85. Now that  
I’m a grown-up, of course, I have a Voyage 200. 🙂

---

<div class="post-metadata">

**Author:** ![rubyist](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/bbe5ce/32.png) [@rubyist](https://www.ruby-forum.com/u/rubyist)\
**Post date:** [February 2, 2006, 7:09am UTC](https://www.ruby-forum.com/t/indentation-vs-end-s/99901/19 "2006-02-02T07:09:01Z")

</div>

removed\_email\_address@domain.invalid wrote:

> 

Not a bad idea in itself. In fact, I think that really old Ruby  
versions (prior to my learning it with 1.4) did something like  
that. When modifiers were introduced (x if y, x while y, etc.)  
parsing became difficult and they were dropped. I think that’s  
the case.

Hal

---

<div class="post-metadata">

**Author:** ![rubyist](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/bbe5ce/32.png) [@rubyist](https://www.ruby-forum.com/u/rubyist)\
**Post date:** [February 2, 2006, 2:22am UTC](https://www.ruby-forum.com/t/indentation-vs-end-s/99901/20 "2006-02-02T02:22:10Z")

</div>

removed\_email\_address@domain.invalid wrote:

> …  
> I understand the importance of indentation, but forcing it on me was  
> really painful. I honestly wanted to stab someone every time I got an  
> error (ruby give me an error too when I missed an end, but it’s somehow  
> different). There is something incredibly soothing about writing  
> freeform and freestyle code in Ruby which I don’t get in Python.

Same here. My editor fills in the ‘end’ stuff for me, so there is no  
extra typing. But I have the freedom to adjust the layout to highlight  
sections of code to better express intent.

> What I’m afraid of now is going to college next year and having to deal  
> with “stricter” languages.

Well, that sinks it: Skip college. Code Ruby.

Actually, experience with a variety of languages is usually a Good  
Thing, at least to give some perspective.

–  
James B.

[http://www.ruby-doc.org](http://www.ruby-doc.org) - Ruby Help & Documentation  
[Ruby Code & Style](http://www.artima.com/rubycs/) - The Journal By & For Rubyists  
[http://www.jamesbritt.com](http://www.jamesbritt.com) - Playing with Better Toys  
[http://www.30secondrule.com](http://www.30secondrule.com) - Building Better Tools

[Next page](https://www.ruby-forum.com/t/indentation-vs-end-s/99901.md?page=2)
