Why not adopt "Python Style" indentation for Ruby?

D

David A. Black

Hi --

I code in ruby and c++.

I love {} in c++.

I love "do", "end" in ruby.

That's just because I am deeply grateful for what both these languages let me
achieve, each in it's own field.

Absolutely. Very few of these "features" really have any absolute
quality of being good or bad, outside of their context.


David

--
Rails training from David A. Black and Ruby Power and Light:
Intro to Ruby on Rails January 12-15 Fort Lauderdale, FL
Advancing with Rails January 19-22 Fort Lauderdale, FL *
* Co-taught with Patrick Ewing!
See http://www.rubypal.com for details and updates!
 
F

Frasier Mruby

I have to mention in the first line of each post. I agree the idea of
closing a code block with something like "END", but suggest to use
something else to replace it such as "{ }".
Have you written to any C mailing lists, suggesting that C adopt
features from Ruby?
If you felt insulted when some people ask if ruby could make improvement
in future on its syntax, I feel sorry for that and think people could be
better off to have an opener mind. Event if I didn't write to any C
mailing list asking C to improve its syntax, but there are much chances
that some other people had written to Java mailing list ask java to
adopt some nice feature from ruby or other languages. That might be the
reason in jdk1.5 there were some syntax improvement like the adoption of
Generics. In future release, Python might have considered to remove
"self" as suggested by someone who wrote to python mailing list. It's a
common scenario that suggestions were brought up to ask the possibility
of syntax improvement,just like the first article in this thread posted
by someone else.
It's been discussed a million times over many years, if that's what
you mean.
If the "END" will not be considered to be replaced, then I suggest ruby
forum people be better off to add a FAQ page so that to prevent other
people from asking the same question again and again, since probably I
am not the only person who are concerned with the "END".
"end" is not a test of whether or not Ruby is an attractive language,
It's a not test, but I, or other may have noticed cases (could be more
potentially) some ruby users' concerns about "END", while relatively
fewer people complaining about the curly braces.

I will take other's advice and use more and get myself familiar with
it.Thank you for your time.
 
D

David A. Black

Hi --

If the "END" will not be considered to be replaced, then I suggest ruby
forum people be better off to add a FAQ page so that to prevent other
people from asking the same question again and again, since probably I
am not the only person who are concerned with the "END".

You can't have a FAQ entry for every aspect of Ruby syntax that
probably won't be changed :)
It's a not test, but I, or other may have noticed cases (could be more
potentially) some ruby users' concerns about "END", while relatively
fewer people complaining about the curly braces.

I think that's because the curly braces are not used, and 'end' is.
People don't complain about things they don't like that aren't in the
language :)


David

--
Rails training from David A. Black and Ruby Power and Light:
Intro to Ruby on Rails January 12-15 Fort Lauderdale, FL
Advancing with Rails January 19-22 Fort Lauderdale, FL *
* Co-taught with Patrick Ewing!
See http://www.rubypal.com for details and updates!
 
R

Robert Klemme

2008/10/7 Frasier Mruby said:
I am kind of new to ruby and like it after looking python first. [...]
I have to mention in the first line of each post. I agree the idea of
closing a code block with something like "END", but suggest to use
something else to replace it such as "{ }".

How about first learning and using the language instead of suggesting
changes right away?
If you felt insulted when some people ask if ruby could make improvement
in future on its syntax, I feel sorry for that and think people could be
better off to have an opener mind.

What about you? How open is your mind?
Event if I didn't write to any C
mailing list asking C to improve its syntax, but there are much chances
that some other people had written to Java mailing list ask java to
adopt some nice feature from ruby or other languages. That might be the
reason in jdk1.5 there were some syntax improvement like the adoption of
Generics. In future release, Python might have considered to remove
"self" as suggested by someone who wrote to python mailing list. It's a
common scenario that suggestions were brought up to ask the possibility
of syntax improvement,just like the first article in this thread posted
by someone else.

Well, but well thought out suggestions with a realistic perspective of
realization need good understanding of the matter. And with changes in
programming language syntax matters are always quite complicated - if
only for the thousands or millions of lines of code that might be
affected.
If the "END" will not be considered to be replaced, then I suggest ruby
forum people be better off to add a FAQ page so that to prevent other
people from asking the same question again and again, since probably I
am not the only person who are concerned with the "END".

You can easily search the archives of this list and find out. Note:
you could have done it /before/ jumping right into the next language
change discussion.
I will take other's advice and use more and get myself familiar with
it.Thank you for your time.

That's a good course of action.

Regards

robert
 
F

Frasier Mruby

Robert said:
What about you? How open is your mind?
"Open", as my understanding, is allowing others to say something and not
forbid them. I won't feel bad, impatient,or angry if other people brings
up suggestions which I don't agree, and won't use sarcastic tones to
reply newbie's messages.
Well, but well thought out suggestions with a realistic perspective of
realization need good understanding of the matter. And with changes in
programming language syntax matters are always quite complicated - if
only for the thousands or millions of lines of code that might be
affected.
That's true. Agree. It's just that Mats mentioned during development of
new releases he expressed the intention of improve the ruby syntax.
You can easily search the archives of this list and find out. Note:
you could have done it /before/ jumping right into the next language
change discussion.

I DID the search /before/ this discussion. I didn't find other
discussion about the replacement of "END". Sorry. This thread is one of
the closest. (You can try searching the "END" in the forum.) If you know
easier way, please let me and other newbies know so that they don't jump
in next time.

Thank you for your time.
 
B

Benoit Daloze

[Note: parts of this message were removed to make it a legal post.]

"Or consider to use use:
"/* */", "|...|", "<...>", "[...]" , "(...)", "((...))", , "//...//", "
:...: ", " '...' ", " `...` " for blocks."
I can't stand with the idea of using other chars than braces {} for a block,
I think it's particular to ruby to write:
names.each { |name| puts name }
I think do...end is a little long for a small block like this.

"My first thought to use brace "{...}" to replace "END" since it's a
popular convention."

Well, if you take the braces, you will have to put one just after the
condition(if, else, ...)
and "{" is often useless I think. If you indent your code, where will you
write the "{" ? after the "if" on the same line ? on a new line ?
That's why I like the "end", one end for everything, and only one place if
you indent.

And the syntax "do(sth) if condition" is fast and logical to write.But I
think we should not use this for long lines for readability reasons.

Regards,
Benoit
 
J

Joe Wölfel

It seems that DSLs in Ruby get some of their power from the optional
nature of parenthesis. I wonder if making 'end' more optional too
would make DSLs yet more powerful and expressive. It might be an
interesting experiment to see what Ruby would look like if 'end' were
optional in places where indentation made it unambiguous. In that
way, it would be consistent with parenthesis being optional.

BTW, the term "domain-specific language" seems inaccurate. Many of
these languages are really double-entendre languages. Their power of
expression seems to come from having two equally good and correct
interpretations - one domain specific and one in Ruby. The double
entendre doesn't just eliminate clutter, it also eliminates the
mental gymnastics required to translate from one language to another.

Dear Mats,

I am kind of new to ruby and like it after looking python first. As
some other people said, my only major complaint is it's many "END".
Among java/c/C++/python, the "END" keep reminding me the inconvenience
of it during coding ruby. I like ruby because it's easy to learn, and
to read. It's designed for be friends of programmers. But I feel the
"END" may have a negative role to ruby's purpose or attraction.

I am fine to have "END" for class or methods. But for IF,WHILE, CASE,
FOR, etc., when there are many levels it often make me confused
what the
matching part of the those "END"s are.

I understand and agree your comment that ruby had better to have
something to close the code block. But I sincerely hope you could come
up something else to replace the "END".

My first thought to use brace "{...}" to replace "END" since it's a
popular convention.

I suggest to use only the "do...end" to formalize the blocks, brace {}
will be stopped to be used. It seems to me it's a waste of symbols to
have two ways to represent blocks, which may not be the most
frequently
used. Or consider to use use:
"/* */", "|...|", "<...>", "[...]" , "(...)", "((...))", ,
"//...//", "
:...: ", " '...' ", " `...` " for blocks.

To enhance readability is probably one of ruby's design purpose and I
really hope some thing could be done earlier to make the "END" looks
prettier.

Thank you!

* tab/space mixture
* templates, e.g. eRuby
* expression with code chunk, e.g lambdas and blocks
* clipboards, email, pastebins, and other places where the code is
not
preserved literally
 
B

Brian Candler

Nobuyoshi said:
Recent 1.9 warns when it see a mismatch.

$ ./ruby -ve 'begin
end'
ruby 1.9.0 (2008-10-07 revision 19704) [i686-linux]
./ruby: warning: mismatched indentations: line 1:'begin' and line
2:'end'

Ooh, that's nice. Now I have a reason to install 1.9 alongside a
production ruby (although I'll be very careful to keep the two separate)

Thanks,

Brian.
 
B

Brian Candler

Yukihiro said:
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.

As an observation, I always found ruby's "then" to be a rather
superfluous non-keyword; that is,

if a == b then
...
end

if a == b
... same
end

if a == b then ...; end

if a == b; ... same; end

So a possible (but highly incompatible) approach would be for "then" to
introduce a single-line block, e.g.

if a == b then puts "hello"; puts "world" # end implied

if a == b
puts "hello"
puts "world"
end

It could also be used, although less obviously, in other constructs:

while !a.empty? then puts a.shift

I'm not sure what 'then' followed immediately by newline should do.

Anyway, this is just an idle thought, as it would break lots of things.
 
B

brabuhr

It could also be used, although less obviously, in other constructs:

while !a.empty? then puts a.shift

"while then"? (kinda sounds funny to my ears :)

And, in this case, is it really better than:
puts a.shift while !a.empty?
 
F

Frasier Mruby

Benoit said:
I can't stand with the idea of using other chars than braces {} >for a block,
I think it's particular to ruby to write:
names.each { |name| puts name }
Does it looks a little better if using square brace? since it LOOKs
more like a "block":
names.each [ |name| puts name ]
I think do...end is a little long for a small block like this.
Agree. do...end is suitable for multiple lines block.

And can curly brace be used replacing "END" while it is kept as it is to
represent blocks? Any parsing difficulty?
where will you write the "{" ? after the "if" on the same line >? on a new line ?
For simplicity reason, I would say put the "{" on the same line of "if".

Thanks for your reply.
 
B

Brian Candler

unknown said:
"while then"? (kinda sounds funny to my ears :)

It does. I was just trying to see what happens if you apply the idea
consistently. I guess taken to extremes you'd also get

def f(x,y) then x+y

which I don't particularly like, but then one-line method definitions
are pretty unusual.

<aside>
I still like that better than "f =-> x,y {x+y}" from 1.9, which is
horrid

I'd much rather have a new keyword: "f = fn(x,y) {x+y}"
And, in this case, is it really better than:
puts a.shift while !a.empty?

No, not really.

It might be useful for 'if' though. I quite often write code with lots
of backwards lines:

something if foo
raise "Error" unless bar
other if baz

and it would be good to write them the right way round. (Although
"unless...then" doesn't really read well either)

More importantly,

if (x = some_big_calculation) then x.something

can't be written in backwards form currently.
 
M

Michael Shigorin

...me too...

I am kind of new to ruby and like it after looking python first.

It might take some time for that particular taste to fade away...
keep on :)
It's designed for be friends of programmers. But I feel the
"END" may have a negative role to ruby's purpose or attraction.

It's very subjective, you might want to have a look at a dozen
more languages (e.g. Modula-2 also uses END with no problem).
* clipboards, email, pastebins, and other places where the
code is not preserved literally

...and teamwork is more nasty since there's one more choke point.


How about first learning and using the language instead of
suggesting changes right away?

It helps in wider sense: while getting acquainted with a new OS,
or with a university lab people who were there before you.
Lurking and learning what is valued in this community and what
is frowned upon helps getting into being valued and not frowned.
Or, well, quitting without much ado -- that's better at times.

It probably could but what you suggest is taking one of the worst
design flaws in Python and planting it into Ruby. It is not an
improvement by any measure.
What about you? How open is your mind?

...e.g. regarding adopting new syntax and comparing it over
a few weeks :)

Good luck, and don't get frustrated :) You'll understand people
who objected after more code behind.... both written and read.


"Open", as my understanding, is allowing others to say
something and not forbid them.

JFYI: some tend to mix up "openness", "freedom" and "impunity".
These are all different things, e.g. I'm not particularly "open"
to badmouthing or brutal wording.
I won't feel bad, impatient,or angry if other people brings up
suggestions which I don't agree

Wonder if you've already tried that couple hundred times on
the same old matter. :) [for sufficient N of matters if you had]
and won't use sarcastic tones to reply newbie's messages.

There's also a problem of time available. As one proverb would
put it, "one can ask so many questions that thousand wizards
won't keep up answering".

So being patient to suggestions one wouldn't agree to is respecting
the other side, but being patient to first learn about something
and then ask why things are this way not the other (and only then
suggesting to fix or improve something) is even more so.


Actually, the more I write in scheme, the more I like its
structure. It all just works.

It's not about structure in the first place, functional languages
differ in approach; syntax is an effect, not the cause. See also
http://mitpress.mit.edu/sicp/

BTW Ruby is a nice language in terms of softly understanding OOP
or FP to those who would do C or shell before. IMO much better
than bare C++ or Java (got headaches), or probably LISP (was too
young when put my nose in it for the first time)...


Have you written to any C mailing lists, suggesting that C adopt
features from Ruby?

Fortuned, sir! :)
 
F

Frasier Mruby

I posted a message in this thread under the circumstances of:

1. I agreed that ruby had better to close the code block using a
keyword. I didn't repeat the topic "why not adopt python style".
2. Some other ruby users (sound have much more ruby experience than me)
has similar concerns about "END". (The author of 1st article in this
thread seems like a ruby core contributor.)
3. Mats expressed his intention since 2006 to experiment new syntax as
alternative for "END". (In 1.9, the ";;" was experimented but abandoned
later.)

So basically I asked if other similar experiment would be made in
future. And I wondered if curly braces "{}" could be considered as an
alternative. For blocks, use "do...end" if multiple lines, use other
chars like "names.each [|name| puts name]" for single line.

|Michael Shigorin said:
It helps in wider sense: while getting acquainted with a new OS,
or with a university lab people who were there before you.
Lurking and learning what is valued in this community and what
is frowned upon helps getting into being valued and not frowned.
So being patient to suggestions one wouldn't agree to is respecting
the other side, but being patient to first learn about something
and then ask why things are this way not the other (and only then
suggesting to fix or improve something) is even more so.

I may not be alone. As I said in 2) above, it seems some
more-experienced ruby users had similar concerns.
It probably could but what you suggest is taking one of the worst
design flaws in Python and planting it into Ruby. It is not an
improvement by any measure.

I appreciate the purpose of "END". I was not suggesting to use python
style from my first post in this thread. Just wondered if there could be
better syntax as an alternative.
BTW Ruby is a nice language in terms of softly understanding OOP
I am excited about ruby,too.
To be frankly, I can imagine if I haven't heard of ruby, and if I can't
find others asking the same question, there are much chances I will send
an email to python group suggesting them to remove the "self" out of
python method argument list. Syntax improvement requests, in my
imagination, is not that an insult to a language, if one consider it's a
suggestion with a good wish to make it better. Maybe I underestimated
language lovers' sensitivities.
There's also a problem of time available. As one proverb would
put it, "one can ask so many questions that thousand wizards
won't keep up answering".

I did the search both in Google and the forum, but didn't find a lot of
discussion about alternative syntax for "END". Since as David A. Black
said (thanks for his reply, by the way), if similar question has been
discussed "a million times", a FAQ page might help for both newbies and
rubist to save everybody's time. A topic discussed a millions times may
suggest it's controversial, or suggest if there's room for improvement.
Apologize for my ignorance if I missed anything.

Thank you for your time.
 
J

Jeremy McAnally

Then you're introducing a big chunk of parser ambiguity. For example

if a == b then puts "hello"; puts "world" # end implied

Do you mean if a==b puts "hello" *AND* puts "world" or should you
output "hello" if it's true and "world" no matter what. That would
put a big load on the parser to figure out the different between the
different line delimiters and how that impacts the code around it.

--Jeremy

As an observation, I always found ruby's "then" to be a rather
superfluous non-keyword; that is,

if a == b then
...
end

if a == b
... same
end

if a == b then ...; end

if a == b; ... same; end

So a possible (but highly incompatible) approach would be for "then" to
introduce a single-line block, e.g.

if a == b then puts "hello"; puts "world" # end implied

if a == b
puts "hello"
puts "world"
end

It could also be used, although less obviously, in other constructs:

while !a.empty? then puts a.shift

I'm not sure what 'then' followed immediately by newline should do.

Anyway, this is just an idle thought, as it would break lots of things.



--
http://jeremymcanally.com/
http://entp.com/
http://omgbloglol.com

My books:
http://manning.com/mcanally/
http://humblelittlerubybook.com/ (FREE!)
 
B

Brian Candler

Jeremy said:
Then you're introducing a big chunk of parser ambiguity. For example

if a == b then puts "hello"; puts "world" # end implied

Do you mean if a==b puts "hello" *AND* puts "world" or should you
output "hello" if it's true and "world" no matter what.

I meant it would be equivalent to

if a == b; puts "hello"; puts "world"; end

(I thought I wrote that out in full)
That would
put a big load on the parser to figure out the different between the
different line delimiters and how that impacts the code around it.

If the rules are clearly defined, parsers are easy to write. It's
certainly much clearer than many of the existing Ruby parsing rules :)
 
R

Ron Fox

I have to say bluntly I completely disagree with this. It's an
example of having learned to use a hammer, requiring all the world to
be a nail.

The concept of 'block' structured languages with block ending is much
more prevalent both in language count and in user count than
indentation with semantic meaning. For that I know of exactly two
languages, Python and Occam.. where Occam is quite a fringe language
these days (and maybe always was if you weren't programming
transputers, but I'm showing my age).

The most important thing to have, when learning a new language, is the
flexibility to adapt, the rules, conventions and idioms of that
language. The thing that stands most in the way of learning a language
is the stubborn requirement that all languages operate in the same
way. They don't won't and for good reasons.

Ron.

Frasier said:
Dear Mats,

I am kind of new to ruby and like it after looking python first. As
some other people said, my only major complaint is it's many "END".
Among java/c/C++/python, the "END" keep reminding me the inconvenience
of it during coding ruby. I like ruby because it's easy to learn, and
to read. It's designed for be friends of programmers. But I feel the
"END" may have a negative role to ruby's purpose or attraction.

I am fine to have "END" for class or methods. But for IF,WHILE, CASE,
FOR, etc., when there are many levels it often make me confused what the
matching part of the those "END"s are.

I understand and agree your comment that ruby had better to have
something to close the code block. But I sincerely hope you could come
up something else to replace the "END".

My first thought to use brace "{...}" to replace "END" since it's a
popular convention.

I suggest to use only the "do...end" to formalize the blocks, brace {}
will be stopped to be used. It seems to me it's a waste of symbols to
have two ways to represent blocks, which may not be the most frequently
used. Or consider to use use:
"/* */", "|...|", "<...>", "[...]" , "(...)", "((...))", , "//...//", "
:...: ", " '...' ", " `...` " for blocks.

To enhance readability is probably one of ruby's design purpose and I
really hope some thing could be done earlier to make the "END" looks
prettier.

Thank you!

* tab/space mixture
* templates, e.g. eRuby
* expression with code chunk, e.g lambdas and blocks
* clipboards, email, pastebins, and other places where the code is not
preserved literally
 
D

David A. Black

Hi --

The most important thing to have, when learning a new language, is the
flexibility to adapt, the rules, conventions and idioms of that language. The
thing that stands most in the way of learning a language is the stubborn
requirement that all languages operate in the same way. They don't won't and
for good reasons.

You might find this interesting:

http://www.infoq.com/articles/coming-from-ruby

Another related matter is the recurrent wish for Ruby to become so
flexible, including in its syntax, that it will support any imaginable
programming paradigm and allow redefinition of every operator, literal
constructor, and keyword. That, too, has never made sense to me. For
one thing, and by definition, the world needs only one
pan-paradigmatic, syntax-agnostic language. Once there's one, there's
no need for a second one. So then the question becomes: should Ruby
take on that role? Or, to look at it another way: should the existence
of the pan-paradigmatic language necessitate the death of an existing
language? And if so, should the doomed language be Ruby?

Once you look at it that way, turning Ruby into language soup makes no
sense at all.

Anyway, a slightly different train of thought, but your comments
brought it to mind.


David

--
Rails training from David A. Black and Ruby Power and Light:
Intro to Ruby on Rails January 12-15 Fort Lauderdale, FL
Advancing with Rails January 19-22 Fort Lauderdale, FL *
* Co-taught with Patrick Ewing!
See http://www.rubypal.com for details and updates!
 
T

The Higgs bozo

David said:
For one thing, and by definition, the world needs only one
pan-paradigmatic, syntax-agnostic language. Once there's one, there's
no need for a second one.

One already exists: it's called Lisp. You've just described Lisp.
So then the question becomes: should Ruby
take on that role? Or, to look at it another way: should the existence
of the pan-paradigmatic language necessitate the death of an existing
language? And if so, should the doomed language be Ruby?

Once you look at it that way, turning Ruby into language soup makes no
sense at all.

Agreed. Ruby should not turn itself into Lisp!

This begs a question, in my mind. Has anyone tried to implement Ruby in
Lisp? (Though I know there are projects for the converse.) It would be
a neat thing to do: generate Lisp code which is the Ruby AST. You
automatically get N implementations of Ruby, from the N implementations
of Lisp. Choose the best one according to whatever criteria, and use
that for the first implementation-specific classes such as sockets.

Claims that it would be too slow would need to be backed up with data.
There is a near endless assortment of optimization techniques which may
be used. Given SBCL is faster or slower than Java depending on the
benchmark, it could potentially be much faster. The AST can be
manipulated at run-time, in ways more far-reaching than the myopic
hotspot algorithms. Potentially.
 
F

Frasier Mruby

David said:
Once you look at it that way, turning Ruby into language soup makes no
sense at all.

I read the article, David. I understand what the article tries to say:
"After you've heard Matz discuss how he thinks about these things, all
the more do you realize that "to make C++ programmers feel more at home"
just isn't in the ballpark."

My intention of syntax improvement on "END" is more like to make less
typing and eye catching to find matching code, rather than to make ruby
feel more like C/C++.

Maybe I didn't make myself clear completely.

I understand as a newbie, Robert and most others suggest me to use ruby
more to see if I have different feeling about "END". But to make my
point more explicit, the intention of my original post is rather than a
syntax suggestion change, but more a support of ruby creator MATS's
intention and experiment (already made) on alternative syntax of "END".
Mats's this syntax experiment likely involved other ruby guru's support
in ruby core team. They are not newbies like me or just casually jumped
in this decision, right?

I just additionally brought about some examples of candidates for the
alternative of keyword "END". I agreed with Robert that those
candidates may not be realistic. Mats has the final decision which I
will support no matter he decide to change or not, or what the new
syntax be like.

To make it short, I am on Mats side, who expressed and experimented a
syntax alternative for "END", while it seems Robert, David and some
others are on a different side with ruby's creator, Mats. That's sounds
a little interesting, huh? :) I apologize for my rush on my some
inappropriate comments/reactions anyway.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top