[prev in list] [next in list] [prev in thread] [next in thread] 

List:       ruby-talk
Subject:    Re: Why not adopt "Python Style" indentation for Ruby?
From:       Tony Arcieri <tony.arcieri () gmail ! com>
Date:       2013-07-30 1:24:35
Message-ID: CAHOTMV+vHkyZrWuayZU+rF8vSA50jMVROzf-MYdxqP75+mAE7A () mail ! gmail ! com
[Download RAW message or body]

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 <flyingkite@edoors.com>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 <matz@ruby-lang.org> 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

[Attachment #3 (text/html)]

<div dir="ltr">There&#39;s something very important to understand about &quot;Python \
style&quot; indentation: Python&#39;s approach is a subset of possible \
indent-sensitive grammars. It&#39;s also incompatible with Ruby.<div>

<br></div><div>Before anything else, I&#39;ll say this: Haskell-style indent \
sensitivity could work with Ruby. So it&#39;s not that Ruby is incompatible with \
indent sensitivity. It&#39;s just the way Python implements it that&#39;s \
incompatible with Ruby.</div>

<div><br></div><div>Python&#39;s indent blocks are all *statements* (i.e. they \
don&#39;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&#39;t embed statements \
inside expressions. </div>

<div><br></div><div>Ruby is a pure expression based language which doesn&#39;t have \
statements. Because of this, Pythonic indent sensitivity simply won&#39;t work, since \
it&#39;s intractably tied to statements.</div><div>

<br></div><div>Again, to fix this, we&#39;d need to use Haskell-style indent \
sensitivity.</div><div><br></div><div><br></div><div><br></div></div><div \
class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Oct 6, 2008 at 10:35 AM, \
Frasier Mruby <span dir="ltr">&lt;<a href="mailto:flyingkite@edoors.com" \
target="_blank">flyingkite@edoors.com</a>&gt;</span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc \
solid;padding-left:1ex">Dear Mats,<br> <br>
I am kind of new to ruby and like it after looking python first.  As<br>
some other people said, my only major complaint is it&#39;s many &quot;END&quot;.<br>
Among java/c/C++/python, the &quot;END&quot; keep reminding me the inconvenience<br>
of it during coding ruby.  I like ruby because it&#39;s easy to learn, and<br>
to read. It&#39;s designed for be friends of programmers.  But I feel the<br>
&quot;END&quot; may have a negative role to ruby&#39;s purpose or attraction.<br>
<br>
I am fine to have &quot;END&quot; for class or methods. But for IF,WHILE, CASE,<br>
FOR, etc., when there are many levels it often make me confused what the<br>
matching part of the those &quot;END&quot;s are.<br>
<br>
I understand and agree your comment that ruby had better to have<br>
something to close the code block. But I sincerely hope you could come<br>
up something else to replace the &quot;END&quot;.<br>
<br>
My first thought to use brace &quot;{...}&quot; to replace &quot;END&quot; since \
it&#39;s a<br> popular convention.<br>
<br>
I suggest to use only the &quot;do...end&quot; to formalize the blocks, brace {}<br>
will be stopped to be used. It seems to me it&#39;s a waste of symbols to<br>
have two ways to represent blocks, which may not be the most frequently<br>
used.  Or consider to use use:<br>
 &quot;/* */&quot;, &quot;|...|&quot;, &quot;&lt;...&gt;&quot;, &quot;[...]&quot; , \
&quot;(...)&quot;, &quot;((...))&quot;, , &quot;//...//&quot;, &quot;<br> :...: \
&quot;, &quot; &#39;...&#39; &quot;, &quot; `...` &quot; for blocks.<br> <br>
To enhance readability is probably one of ruby&#39;s design purpose and I<br>
really hope some thing could be done earlier to make the &quot;END&quot; looks<br>
prettier.<br>
<br>
Thank you!<br>
<br>
 On 18/05/07, Yukihiro Matsumoto &lt;<a \
href="mailto:matz@ruby-lang.org">matz@ruby-lang.org</a>&gt; wrote:<br> &gt;   * \
tab/space mixture<br> &gt;   * templates, e.g. eRuby<br>
&gt;   * expression with code chunk, e.g lambdas and blocks<br>
 * clipboards, email, pastebins, and other places where the code is not<br>
 preserved literally<br>
<span class="HOEnZb"><font color="#888888"><br>
--<br>
Posted via <a href="http://www.ruby-forum.com/" \
target="_blank">http://www.ruby-forum.com/</a>.<br> <br>
</font></span></blockquote></div><br><br clear="all"><div><br></div>-- <br>Tony \
Arcieri<br> </div>



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic