From: Dan Moniz Date: 2001-07-06T10:06:01+09:00 Subject: [ruby-talk:17359] Re: /* */ comments >David Alan Black wrote: > >> # { >> This might be one way >> to do it, without looking >> too C-like. >> } > >That's neat - it'd also let you comment out blocks of code quickly and >easily. Even nicer would be a mechanism where commenting out the line >containing a block command could comment the whole block upto the 'end' >statement. You'd need an explicit block comment symbol, rather than using >#, so that it doesn't break anything like > > # if a > if b #let's not use a for the time being > do this > end Even being an old Lisp hand, I'm somewhat fond of the Haskell way of commenting, which is roughly thus: -----start: toy_square.hs----- {- This is a comment block in a traditional Haskell script. The code below is some toy code that makes size an integer (Int) defined to be the sum of five and six, and then defines a function to square the integer. -} -- This is a "end-of-line" comment in a traditional Haskell script, -- below is some toy code: size :: Int size = 5+6 square :: Int -> Int square n = n*n -----stop: toy_square.hs----- On the other hand, Haskell also supports "literate" scripts, which in comparison to traditional look like this, roughly: -----start: toy_square.lhs----- This is a comment block in a literate Haskell script. The code below is some toy code that makes size an integer (Int) defined to be the sum of five and six, and then defines a function to square the integer. Note that I can write comments freely without notation in literate scripts. As seen below, there is no difference between "end-of-line" comments and comment blocks (the indentation, both in this script and the previous one [in the comment block] is purely for my enjoyment and has no bearing). This is a "end-of-line" comment in a literate Haskell script. Below is some toy code. Notice the > at the beginning of each line of code. > size :: Int > size = 5+6 > square :: Int -> Int > square n = n*n -----stop: toy_square.lhs----- In the literate style, everything is a comment unless explicitly noted otherwise. Literate Haskell has nothing to do (directly, anyway) with document generation from code (unlike the use of =begin and =end for rdtool). Note that the difference is also reflected in filename extension. ".hs" scripts are in traditional format, ".lhs" are in literate format. Haskell interpreters and compilers pick up on this (the filenames are in the series of "start" and "stop" hyphen seperators -- that's all me, added for clarity in the context of the email; Haskell doesn't use them). In Haskell, the {- -} style can enclose other comments; they are nested. I think it would be neat to see some of this in Ruby from my perspective as relates to style, but it may look ugly to others. I think it's useful as well, but in general, I don't have a problem commenting out entire blocks of code with # (Like I said, I'm a Lisp guy, I use XEmacs and Emacs-ish editors). On the other hand, what about merely changing parse.y as was originally done by dv and writing a utility to convert code to standard form before you release it to anyone else? Non-optimal, maybe, but easy for everyone involved and doesn't necessitate a language change. -- Dan Moniz [http://www.pobox.com/~dnm/]