From: Tony Arcieri Date: 2013-07-30T10:24:35+09:00 Subject: Re: Why not adopt "Python Style" indentation for Ruby? --047d7b676e1cac440104e2b078e7 Content-Type: text/plain; charset=ISO-8859-1 There's something very important to understand about "Python style" indentation: Python's approach is a subset of possible indent-sensitive grammars. It's also incompatible with Ruby. Before anything else, I'll say this: Haskell-style indent sensitivity could work with Ruby. So it's not that Ruby is incompatible with indent sensitivity. It's just the way Python implements it that's incompatible with Ruby. Python's indent blocks are all *statements* (i.e. they don't return a value). This means that you cannot embed anything indent sensitive inside any *expression* (which does return a value) This makes it impossible to e.g. put an if statement inside of a Python lambda, since you can't embed statements inside expressions. Ruby is a pure expression based language which doesn't have statements. Because of this, Pythonic indent sensitivity simply won't work, since it's intractably tied to statements. Again, to fix this, we'd need to use Haskell-style indent sensitivity. On Mon, Oct 6, 2008 at 10:35 AM, Frasier Mruby wrote: > 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! > > On 18/05/07, Yukihiro Matsumoto wrote: > > * 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 > > -- > Posted via http://www.ruby-forum.com/. > > -- Tony Arcieri --047d7b676e1cac440104e2b078e7 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
There's something very important to understand about &= quot;Python style" indentation: Python's approach is a subset of p= ossible indent-sensitive grammars. It's also incompatible with Ruby.
Before anything else, I'll say this: Haskell-style inden= t sensitivity could work with Ruby. So it's not that Ruby is incompatib= le with indent sensitivity. It's just the way Python implements it that= 's incompatible with Ruby.

Python's indent blocks are all *statements* (i.e. t= hey don't return a value). This means that you cannot embed anything in= dent sensitive inside any *expression* (which does return a value) This mak= es it impossible to e.g. put an if statement inside of a Python lambda, sin= ce you can't embed statements inside expressions.=A0

Ruby is a pure expression based language which doesn= 9;t have statements. Because of this, Pythonic indent sensitivity simply wo= n't work, since it's intractably tied to statements.

Again, to fix this, we'd need to use Haskell-style inden= t sensitivity.





On Mon, Oct 6, 20= 08 at 10:35 AM, Frasier Mruby <flyingkite@edoors.com> wr= ote:
Dear Mats,

I am kind of new to ruby and like it after looking python first. =A0As
some other people said, my only major complaint is it's many "END&= quot;.
Among java/c/C++/python, the "END" keep reminding me the inconven= ience
of it during coding ruby. =A0I like ruby because it's easy to learn, an= d
to read. It's designed for be friends of programmers. =A0But I feel the=
"END" may have a negative role to ruby's purpose or attractio= n.

I am fine to have "END" for class or methods. But for IF,WHILE, C= ASE,
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, bra= ce {}
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. =A0Or consider to use use:
=A0"/* */", "|...|", "<...>", "[..= .]" , "(...)", "((...))", , "//...//", &= quot;
:...: ", " '...' ", " `...` " for blocks.<= br>
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" lo= oks
prettier.

Thank you!

=A0On 18/05/07, Yukihiro Matsumoto <matz@ruby-lang.org> wrote:
> =A0 * tab/space mixture
> =A0 * templates, e.g. eRuby
> =A0 * expression with code chunk, e.g lambdas and blocks
=A0* clipboards, email, pastebins, and other places where the code is not =A0preserved literally

--
Posted via http://= www.ruby-forum.com/.




-- Tony Arcieri
--047d7b676e1cac440104e2b078e7--