[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: Why not adopt "Python Style" indentation for Ruby?

Yukihiro Matsumoto

5/18/2007 1:37:00 PM

Hi,

In message "Re: Why not adopt "Python Style" indentation for Ruby?"
on Fri, 18 May 2007 22:01:13 +0900, Daniel Martin <martin@snowplow.org> writes:

|Note that the Haskell folks have managed to evolve a language in which
|python-like spacing can be used to mark the extent of discrete code
|chunks, but so can traditional braces.

I admit Haskell syntax is much better than Python's. But I am not yet
sure if it can be applied to Ruby.

matz.

29 Answers

Robert Klemme

5/18/2007 1:56:00 PM

0

On 18.05.2007 15:36, Yukihiro Matsumoto wrote:
> Hi,
>
> In message "Re: Why not adopt "Python Style" indentation for Ruby?"
> on Fri, 18 May 2007 22:01:13 +0900, Daniel Martin <martin@snowplow.org> writes:
>
> |Note that the Haskell folks have managed to evolve a language in which
> |python-like spacing can be used to mark the extent of discrete code
> |chunks, but so can traditional braces.
>
> I admit Haskell syntax is much better than Python's. But I am not yet
> sure if it can be applied to Ruby.

Just to throw in my 0.02EUR here: I don't think it's worth the effort
(which I guess is huge) because Ruby's syntax *is* concise already. If
I got to decide I would rather see those efforts go into JVM based Ruby
implementations and / or native threads. But that's just my personal
preference.

Kind regards

robert

Jaroslaw Zabiello

5/18/2007 3:14:00 PM

0

Dnia Fri, 18 May 2007 22:36:58 +0900, Yukihiro Matsumoto napisa3(a):

> I admit Haskell syntax is much better than Python's.

Matz, you must be joking... Python is much easier to read than Haskell.

--
Jaros3aw Zabie33o
http://blog.za...

Eric Mahurin

5/18/2007 3:20:00 PM

0

On 5/18/07, Yukihiro Matsumoto <matz@ruby-lang.org> wrote:
> Hi,
>
> In message "Re: Why not adopt "Python Style" indentation for Ruby?"
> on Fri, 18 May 2007 22:01:13 +0900, Daniel Martin <martin@snowplow.org> writes:
>
> |Note that the Haskell folks have managed to evolve a language in which
> |python-like spacing can be used to mark the extent of discrete code
> |chunks, but so can traditional braces.
>
> I admit Haskell syntax is much better than Python's. But I am not yet
> sure if it can be applied to Ruby.
>
> matz.

I've picked up on python in the last couple months and like the
indentation. In addition to forced readablity, I find another
practical benefit is that it eliminates hard to track down syntax
errors due to matching {}, begin/end, etc. In ruby, C, perl, etc
these errors can be painful to track down in a large file with lots of
blocks within blocks.

Syntactically it isn't too difficult once you have the lexer generate
indent and unindent tokens. Then the parser just looks for matching
indent and unindent tokens instead of {} or begin/end, etc.

You might consider something like this as an alternative block syntax.
Maybe a ":" followed by a newline (and extra indentation) would start
this style. I'm not sure of a clean way to handle arguments though.

p.s. in the late eighties I made a little shell language (for the
Atari ST) that used indentation just like python.

Filipe Fernandes

5/18/2007 3:40:00 PM

0

On 5/18/07, Eric Mahurin <eric.mahurin@gmail.com> wrote:
<snip>
> I've picked up on python in the last couple months and like the
> indentation. In addition to forced readablity, I find another
> practical benefit is that it eliminates hard to track down syntax
> errors due to matching {}, begin/end, etc. In ruby, C, perl, etc
> these errors can be painful to track down in a large file with lots of
> blocks within blocks.

You could always run it through a tool to clean up code and provide
proper indentation. I personally don't like it when a language
dictates how my code ought to look, since I'm pretty picky myself :s

> Syntactically it isn't too difficult once you have the lexer generate
> indent and unindent tokens. Then the parser just looks for matching
> indent and unindent tokens instead of {} or begin/end, etc.

When working in a team, regardless of how the code has been formatted,
I've always been able to slap pieces of code together and not worry
about indentation (when such language doesn't worry about
indentation). Working in python always adds a little extra stress
when mixing and matching code, and the problem gets bigger when
indentation isn't standardized across teams or when applying code from
the web.

filipe

Austin Ziegler

5/18/2007 4:20:00 PM

0

On 5/18/07, Eric Mahurin <eric.mahurin@gmail.com> wrote:
> On 5/18/07, Yukihiro Matsumoto <matz@ruby-lang.org> wrote:
> I've picked up on python in the last couple months and like the
> indentation. In addition to forced readablity, I find another
> practical benefit is that it eliminates hard to track down syntax
> errors due to matching {}, begin/end, etc. In ruby, C, perl, etc
> these errors can be painful to track down in a large file with lots of
> blocks within blocks.

Scope indicated by whitespace is an indication, IMO, that the compiler
thinks that it knows better than you do.

Always a mistake.

I want a programming language that works how I do; I don't want to
have to work how a stupid programming language requires it.

(I sometimes put debug statements flush left so that it's a simple
/^p<CR> to search for them. Can't do that with scope controlled by
whitespace. Dumb, dumb, dumb, dumb.)

-austin
--
Austin Ziegler * halostatue@gmail.com * http://www.halo...
* austin@halostatue.ca * http://www.halo...feed/
* austin@zieglers.ca

Eric Mahurin

5/18/2007 4:59:00 PM

0

On 5/18/07, Austin Ziegler <halostatue@gmail.com> wrote:
> On 5/18/07, Eric Mahurin <eric.mahurin@gmail.com> wrote:
> > On 5/18/07, Yukihiro Matsumoto <matz@ruby-lang.org> wrote:
> > I've picked up on python in the last couple months and like the
> > indentation. In addition to forced readablity, I find another
> > practical benefit is that it eliminates hard to track down syntax
> > errors due to matching {}, begin/end, etc. In ruby, C, perl, etc
> > these errors can be painful to track down in a large file with lots of
> > blocks within blocks.
>
> Scope indicated by whitespace is an indication, IMO, that the compiler
> thinks that it knows better than you do.
>
> Always a mistake.
>
> I want a programming language that works how I do; I don't want to
> have to work how a stupid programming language requires it.
>
> (I sometimes put debug statements flush left so that it's a simple
> /^p<CR> to search for them. Can't do that with scope controlled by
> whitespace. Dumb, dumb, dumb, dumb.)

That is the exact same case I find the indentation thing gets in the
way. I had to change my way of putting in print debug statements
(same as yours). Every language makes you change your ways a bit. Of
course python's debug facilities (pdb) are much better than ruby's so
I don't do print debugging as much.

I would rather have multiple ways to specify blocks:
* {}'s
* indentation
* in-line (single statement/expression)

BTW, python's lambda sucks! You can't put generic code in there - it
must be a single expression. I think it has to do with the
indentation thing. Only statements can have code blocks (using
indentation) and a lambda is an expression. I don't like the clear
separation of statements and expressions that python has. I think it
all comes back to the indentation thing. They didn't do it right.
Sounds like Haskell did (but I have no experience with it).

gga

5/18/2007 5:21:00 PM

0

On May 18, 12:19 pm, "Eric Mahurin" <eric.mahu...@gmail.com> wrote:
> On 5/18/07, Yukihiro Matsumoto <m...@ruby-lang.org> wrote:
>
> > Hi,
>
> > In message "Re: Why not adopt "Python Style" indentation for Ruby?"
> > on Fri, 18 May 2007 22:01:13 +0900, Daniel Martin <mar...@snowplow.org> writes:
>
> > |Note that the Haskell folks have managed to evolve a language in which
> > |python-like spacing can be used to mark the extent of discrete code
> > |chunks, but so can traditional braces.
>
> > I admit Haskell syntax is much better than Python's. But I am not yet
> > sure if it can be applied to Ruby.
>
> > matz.
>
> I've picked up on python in the last couple months and like the
> indentation. In addition to forced readablity, I find another
> practical benefit is that it eliminates hard to track down syntax
> errors due to matching {}, begin/end, etc. In ruby, C, perl, etc
> these errors can be painful to track down in a large file with lots of
> blocks within blocks.

No, it is just the other way around. Languages that use curly braces
for indentation like C, Perl, etc. are EASY to work with once code is
not properly factored and it extends outside a single page. Ruby is
easy only when you use {, not so much when you use do/end,
unfortunately, as most editors know nothing about it. Some good
editors (emacs, for example), can tell you the context you are in the
modeline with curly braces, but not so with other block indentation
types. And most editors can easily find matching braces. No editor I
am aware knows how to match indentation yet or do/end contexts (not
that it could not be coded, thou).

Python is a true nightmare to debug and understand once you have code
that trails off a single page. A good example of these problems, for
example, is the Maya Python API which is as ugly as it can be, using
all of the ugliest things of python (tabulation using tabs, lots of
underscore methods, lots of code that is not easily refactored, etc).

Another problem with indentation only that has not been mentioned is
that simple cut and paste of source code between two files is not
guaranteed to work (and often will lead to a syntax error or worse, a
runtime error). This to me is still a big no-no for indentation only,
as most programmers *do* often cut and paste code from different
contexts or files. With languages that use braces or Ruby's do/end
you really don't have to worry about that, for the most part.

Jeremy Henty

5/18/2007 5:41:00 PM

0

On 2007-05-18, gga <GGarramuno@aol.com> wrote:

> No editor I am aware knows how to match indentation yet or do/end
> contexts (not that it could not be coded, thou).

Emacs + ruby-mode.el understands do/end just fine.

Regards,

Jeremy Henty

Austin Ziegler

5/18/2007 6:50:00 PM

0

On 5/18/07, gga <GGarramuno@aol.com> wrote:
> No, it is just the other way around. Languages that use curly braces
> for indentation like C, Perl, etc. are EASY to work with once code is
> not properly factored and it extends outside a single page. Ruby is
> easy only when you use {, not so much when you use do/end,
> unfortunately, as most editors know nothing about it. Some good
> editors (emacs, for example), can tell you the context you are in the
> modeline with curly braces, but not so with other block indentation
> types. And most editors can easily find matching braces. No editor I
> am aware knows how to match indentation yet or do/end contexts (not
> that it could not be coded, thou).

Vim does this just fine.

-austin
--
Austin Ziegler * halostatue@gmail.com * http://www.halo...
* austin@halostatue.ca * http://www.halo...feed/
* austin@zieglers.ca

enduro

5/18/2007 9:23:00 PM

0

Eric Mahurin schrieb:

> You might consider something like this as an alternative block syntax.
> Maybe a ":" followed by a newline (and extra indentation) would start
> this style. I'm not sure of a clean way to handle arguments though.


What about another syntax:
Putting a special character at the beginning of every line that is
governed by significant whitespace.
Thes would cause no problems with normal Ruby syntax,
but would provide a way to use significant indentation if one really
wants to.

If "~" were that special character, it would look like that:
~ 5.times do |n|
~ n.times do
~ print n
~ puts

Of course, hardly any editor would be prepared to support this,
currently...

This approach would have the additional advantage
of being more robust to contexts where leading whitespace
gets stripped.


Cheers
Sven