ruby picture

RCR 266: until_eof

Submitted by Malte (Sun Jul 18 11:07:10 UTC 2004)

Abstract

Introduce the keyword until_eof, which you use like this:

module XY until_eof

It is used to let the end of the source file be a replacement for the keyword end.

Problem

You often have ruby source files looking like this:

(First line)    class XY
                    # lots of indented
                  # code goes here
(Last line)     end

Such files have got two disadvantages:

  <li>You have lots of indented code, i.e. waste of space, and </li>
  <li>When looking at such a file and reading the word "end", you have to look at the beginning of the file to know what it is for.</li>

Proposal

Introduce the keyword until_eof, which works like this:

module XY until_eof
  1. Lots of code within XY
  2. until the end of the file

which is a replacement for
module XY

    
    # Lots of code within XY
end

Analysis

This syntax change is a short-hand for a typical ruby idiom.

Implementation

ruby picture
Comments Current voting

Use a folding editor and most of the issues with this go away. -- Austin Ziegler


Hm. So why has Ruby got a clear syntax? We don't need it using editors with syntax highlighting. --Malte


To try to be clearer: "Issues." I don't personally see a real issue here. Look at Diff::LCS; I have not only divided the module up in multiple pieces within a single file, but I have taken advantage of the ability to simply do: "module Diff::LCS" after I have done "module Diff\nmodule LCS" earlier in the file. This reduces the amount of indentation (necessary, because I also have a "class << self" present). I also use Vim, which folds the Ruby code for me so that I only need to see the parts that I am immediately concerned with. I don't see an issue with the way that Ruby does this, especially not one that requires a change to the Ruby interpreter just to accommodate a stylistic preference. -- Austin Ziegler


I'm opposed to this RCR because it's a kind of workaround for something that I don't think is a problem. Every language has *some* constraints and requirements as to its appearance. I don't think a language-level construct can or should be introduced to cater to all tastes. -- David Black


Theoretically, it would be quite easy to implement in the core the ability to close all lexical node definitions at the eof / __END__ keyword, if they aren't already closed. This would make it harder to catch certain bugs, but such a feature would probably be turned off in a "strict" mode. I don't like the keyword implementation, however, as Ruby doesn't need any more keywords, and could probably do with fewer. --Zallus Kanite


Strongly opposed 7
Opposed 1
Neutral 0
In favor 0
Strongly advocate 0
ruby picture
If you have registered at RCRchive, you may now sign in below. If you have not registered, you may sign up for a username and password. Registering enables you to submit new RCRs, and vote and leave comments on existing RCRs.
Your username:
Your password:

ruby picture

Powered by .