Indentation vs. "end"s

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

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?

“Rubyist” [email protected] wrote in message
news:[email protected]

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

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.

In article [email protected],
Jeffrey S. [email protected] 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

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!

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.

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.

-Rubyist [email protected]:

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

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 :stuck_out_tongue:

2006/2/1, Phil T. [email protected]:

Rubyist [email protected] wrote:

[email protected] 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.

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. - [email protected] - http://segment7.net
This implementation is HODEL-HASH-9600 compliant

http://trackmap.robotcoop.com

2006/2/1, Rubyist [email protected]:

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

On 01/02/06, Rubyist [email protected] 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

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

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

“Rubyist” [email protected] 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.

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. :wink:

On Wednesday 01 February 2006 22:37, [email protected] 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”…

On 01/02/06, Rubyist [email protected] 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

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 :stuck_out_tongue:

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. :slight_smile:

[email protected] 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

[email protected] 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 - Ruby Help & Documentation
Ruby Code & Style - The Journal By & For Rubyists
http://www.jamesbritt.com - Playing with Better Toys
http://www.30secondrule.com - Building Better Tools