Whitespace dependence - old topic?

I moved to Ruby about six months ago so I’m weak on history and
community context. I’ve searched the Talk and Core Archives (and done
some Googling) and haven’t found anything relevant to a question which
has been on my mind recently.

NB: I am not interested in a greater [pointless flame-bait] argument
about how Ruby compares to Python or any other language so you can leave
your flame-retardant pants in the other room.


I am interested if the Ruby community has ever had a conversation about
what whitespace interpretation could do for clarity and readability in
the language. My guess is that his idea HAS already been raised, and
discussed, and rejected. Can anyone provide references to such
discussions?

If not, here’s a brief sample of what I’m talking about:

Current:

def MyClass

  def do_stuff
    @my_array.each { |elt| puts elt }
  end

  def do_stuff_foo
    @my_array.each do |elt|
      puts elt.foo
    end
  end

end

Proposed:

def MyClass

  def do_stuff
    @my_array.each { |elt| puts elt }

  def do_stuff_foo
    @my_array.each do |elt|
      puts elt.foo

I recognize that this would represent a huge and controversial breaking
change, and I also recognize that the only way to know for sure is to
try it in a fork and see what happens (easier said than done) but the
merits and demerits of whitespace dependence, esp. relative to Ruby
specifically, seems like an intriguing topic.

Looking forward to lots of reading!
Cheers,
-Chris

Try this:
http://blade.nagaokaut.ac.jp/cgi-bin/vframe.rb?key=significant+whitespace&cginame=namazu.rb&submit=Search&dbname=ruby-talk&max=50&whence=0

It has been discussed before …

Good luck,
Doug

Subject: Whitespace dependence - old topic?
Date: Mon 12 May 14 01:04:41PM -0400

Quoting Chris T. ([email protected]):

NB: I am not interested in a greater [pointless flame-bait] argument
about how Ruby compares to Python or any other language so you can leave
your flame-retardant pants in the other room.

Mah. You put your finger square on the #1 reason why I found Python
unusable - even before Ruby was created. How could this sort of
comparison ever hope to be escaped?

If you are happy about having a mistaken, hardly detectable, whitespace
deletion or insertion deeply change the semantics of your code,
Python is there at your service. Luckily with Ruby I do not run that
risk.

Carlo

Try this:
http://blade.nagaokaut.ac.jp/cgi-bin/vframe.rb?key=significant+whitespace&cginame=namazu.rb&submit=Search&dbname=ruby-talk&max=50&whence=0

It has been discussed before …

Thanks Doug, exactly what I was after!

I just want to reply to what Carlo wrote:

If you are happy about having a mistaken, hardly detectable,
whitespace deletion or insertion deeply change the semantics
of your code, Python is there at your service. Luckily with
Ruby I do not run that risk.

Python is not Ruby, with or without whitespace.

There are so many differences in philosophy, it is very dumb
of you to want to narrow it down solely on whitespace, Carlo,
as already pointed out by 7stud above.

As for the topic itself:

I would like to have an optional, non-default indent-based
interpretation of ruby code. Because whenever I type “end”
it gives me zero information I need when I already indent
it. It is just there to satisfy the ruby parser so it
won’t get confused.

I’d love to have a per-file togglable flag - I would use
whitespace significant only for small standalone classes
like:

class Cat

def initialize(i = ‘black’)
@colour_of_fur = i

These would be only 3 lines my brain has to parse.

In current ruby, I must add at least two lines, and probably
one empty “\n” for clarity (since I added an extra newline
after “class Cat” too".

This could be like a flag -indent or similar in the
shebang line.

I do not think that matz is likely to add this though,
and there is one good point to make:

Parsers for programming languages really should not
choke over whitespace issue and fail because of
that.

Guido once said that this would be the single change
he would undo if he were to design python from
scratch today.

If you are happy about having a mistaken, hardly detectable,
whitespace deletion or insertion deeply change the semantics of your code,

And…If you are happy about having a mistaken, hardly detectable
missing ‘end’ produce this error:

1.rb:2081: syntax error, unexpected $end, expecting keyword_end

…and relish looking through 2,000 lines of code and nests of ‘end’
statements for a missing ‘end’, then Ruby is there at your service.
Ha!

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs