Issue #5054 has been updated by Kurt  Stephens.


What other languages, besides Python, have this feature of "close N blocks of code"?  I *do* see value for this feature in interactive IRB sessions.

However, there are two different mechanisms going on when humans read code.  The eye sees the whole structure at once; the mind reads the tokens serially.  The nested visual structure of well-formatted code maps *directly* to the nested computational semantics.  The loss of visual cues of indentation is different than the cognitive benefits of terse code.  The eye cannot understand "ennnnnd" as fast as:

        end
      end
    end
  end
end

The "   end" tells the eye (and cursor) when to stop due to its relative horizontal position to the code above it -- editors and people take advantage of this convention across *many* programming languages.  A cascade of closing "ends" can be scanned quickly with the eye, in practice about 3-5 lines "end".

Some of us have been "seeing" code by indention for *decades*, our eyes are already trained for it.  Likewise, I find it harder and harder to understand code that is not colorized, it's easier to see patterns of colors and shape than to read tokens.

Properly indented LISP is far more readable than non-indented LISP: eyes naturally see structure, not abstract tokens --
LISP is nested semantic tokens all the way down, but eye needs visual support.  Try reading Old English without punctuation.  Compare Ruby code with/without horizontal white space around  sigils.

Having "end" indent to the same position as the opening block allows search for things like /^\s{4}(if|while|end)/ etc -- it's simple for tools to scan for it lexically, instead of grammatically.

Designing a good syntax is hard.  Changing a good syntax is even harder.

Sincerely,
Kurt



----------------------------------------
Feature #5054: Compress a sequence of ends
http://redmine.ruby-lang.org/issues/5054

Author: ANDO Yasushi ANDO
Status: Open
Priority: Normal
Assignee: 
Category: 
Target version: 


Though as matz said at rubykaigi2011 ruby is a quite good language, many people hate a long sequence of `end' like this:

module MyModule
  class MyClass
    def my_method
      10.times do
        if rand < 0.5 
          p :small
        end 
      end 
    end 
  end 
end

So, I'd like to propose introducing a special keyword, en(n+)d. Using this keyword, we can rewrite the above example like this:

module MyModule
  class MyClass
    def my_method
      10.times do
        if rand < 0.5 
          p :small
        ennnnnd 

I know matz's already rejected a python-style block. He wrote:

> it works badly with
>   * tab/space mixture
>   * templates, e.g. eRuby
>   * expression with code chunk, e.g lambdas and blocks
http://www.ruby-forum.com/topic/108457

These bad things won't occur by introducing en(n+)d.

Some implementations already exists.

JRuby
- https://gist.github.com/1088363

CRuby
- http://www.atdot.net/sp/raw/kn9iol
- http://d.hatena.ne.jp/ku-ma-me/20110718/p1

Thanks for your consideration.


-- 
http://redmine.ruby-lang.org