Multiline comments?

I’m new to Ruby and I’m wondering that there is no possibility to write
comments over more than one line. Just like in C for example with
/* this is a
multiline comment */

Is there any possibility to do this or is there a fundamental
(architectural or whatever) problem?

Christoph

···


Christoph Tapler
christoph_tapler@gmx.net
( Please replace the underline with a dot. )

Christoph Tapler wrote:

I’m new to Ruby and I’m wondering that there is no possibility to write
comments over more than one line. Just like in C for example with
/* this is a
multiline comment */

Is there any possibility to do this or is there a fundamental
(architectural or whatever) problem?

Christoph


Christoph Tapler
christoph_tapler@gmx.net
( Please replace the underline with a dot. )

You can use =begin and =end.

class Foo
=begin
This isn’t a real class
I just made it up for this post
=end
def initialize
puts “blah, blah”
end
end

Regards,

Dan

I’m new to Ruby and I’m wondering that there is no possibility to write
comments over more than one line. Just like in C for example with
/* this is a
multiline comment */

Is there any possibility to do this or is there a fundamental
(architectural or whatever) problem?

The nearest you can come is =begin and =end.
Other than that, you just comment each line.

I don’t think it’s a major architectural problem;
more that Matz has not seen a significant need
for multiline comments. It has been discussed
some.

The only time I miss them is when I (rarely)
want to put a comment in the middle of a line.

Hal

···

----- Original Message -----
From: “Christoph Tapler” christoph.tapler@gmx.net
Newsgroups: comp.lang.ruby
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Sent: Monday, June 16, 2003 9:14 AM
Subject: Multiline comments?


Hal Fulton
hal9000@hypermetrics.com

def dnl(*args); nil end
dnl <<EOF
This is a
multiline comment
EOF

Might not solve really what you want though!

Guillaume.

···

On Mon, 2003-06-16 at 10:14, Christoph Tapler wrote:

I’m new to Ruby and I’m wondering that there is no possibility to write
comments over more than one line. Just like in C for example with
/* this is a
multiline comment */

Is there any possibility to do this or is there a fundamental
(architectural or whatever) problem?

Christoph


Christoph Tapler
christoph_tapler@gmx.net
( Please replace the underline with a dot. )

Saluton!

  • Christoph Tapler; 2003-06-16, 20:53 UTC:

I’m new to Ruby and I’m wondering that there is no possibility to
write comments over more than one line. Just like in C for example
with
/* this is a
multiline comment */

Is there any possibility to do this or is there a fundamental
(architectural or whatever) problem?

The only acceptable application for multiline comments is commenting
out part of a program. That can be done by means of

=begin
=end

For every other purpose ‘from mark to end of line’ comments are a
matter of common sense. This has two aspects:

A mark is necessary to avoid surprising behavior of programs. I
remember a math student who almost went crazy because his F90 program
did print unexpected results. What had happened? He did use the wrong
compiler options so that the program was compiled as a F77 one with
anything behind column 72 being ignored. The problem was that that
left a valid program. He had been searching for the bug for hours
because they only did teach them Fortran 90 so he didn’t know of that
issue.

The lack of an end marker is advantageous because if you cannot
forget or misspell it there is no chance that the commented region
accidentally is larger than expected.

Both problems could be avoided if all people would use an editor that
is capable of syntax highlighting but unfortunately many don’t :-<

Taking a pragmatic point of view there is no reason not to use
single-line comments. If modern editors break lines they also add a
comment character.

Josef ‘Jupp’ Schugt

Here is a little benchmark for comments that were discussed here,

$ ruby1.7 comments.rb
user system total real
default comment 0.140000 0.000000 0.140000 ( 0.141877)

comment 0.140000 0.000000 0.140000 ( 0.133724)

EOF comment 0.500000 0.020000 0.520000 ( 0.633371)
""" comment 0.520000 0.010000 0.530000 ( 0.579245)

I know that times i’m repeating code are too big for default case we use
comments in, but if it will be used i.e. in a function executed from
1…999999.each i guess runtime will be the same.

P.S. Maybe i’m totally wrong and it’s not even worth speaking about it :slight_smile:

That’s my code (i’m sure it sucks, but anyway):

#!/usr/bin/ruby

require "benchmark"
include Benchmark

bm(15) { |x|
x.report(“default comment”) {
100000.times {
=begin
#------------------------------------------------------------ Array#slice

arr.slice( anInteger ) -> anObject

arr.slice( start, length ) -> aSubArray

arr.slice( aRange ) -> aSubArray

···

#------------------------------------------------------------------------

Synonym for Array#[ ].

a = [ “a”, “b”, “c”, “d”, “e” ]

a.slice(2) + a.slice(0) + a.slice(1) #=> “cab”

a.slice(6) #=> nil

a.slice(1, 2) #=> [“b”, “c”]

a.slice(1…3) #=> [“b”, “c”, “d”]

a.slice(4…7) #=> [“e”]

a.slice(6…10) #=> nil

a.slice(-3, 3) #=> [“c”, “d”, “e”]

=end
}
}
x.report("# comment") {
100000.times {
#------------------------------------------------------------ Array#slice

arr.slice( anInteger ) -> anObject

arr.slice( start, length ) -> aSubArray

arr.slice( aRange ) -> aSubArray

#------------------------------------------------------------------------

Synonym for Array#[ ].

a = [ “a”, “b”, “c”, “d”, “e” ]

a.slice(2) + a.slice(0) + a.slice(1) #=> “cab”

a.slice(6) #=> nil

a.slice(1, 2) #=> [“b”, “c”]

a.slice(1…3) #=> [“b”, “c”, “d”]

a.slice(4…7) #=> [“e”]

a.slice(6…10) #=> nil

a.slice(-3, 3) #=> [“c”, “d”, “e”]

}

}
x.report(“EOF comment”) {
100000.times {
<<EOF
------------------------------------------------------------ Array#slice
arr.slice( anInteger ) -> anObject
arr.slice( start, length ) -> aSubArray
arr.slice( aRange ) -> aSubArray

Synonym for Array#[ ].
a = [ “a”, “b”, “c”, “d”, “e” ]
a.slice(2) + a.slice(0) + a.slice(1) #=> “cab"
a.slice(6) #=> nil
a.slice(1, 2) #=> [“b”, “c”]
a.slice(1…3) #=> [“b”, “c”, “d”]
a.slice(4…7) #=> [“e”]
a.slice(6…10) #=> nil
a.slice(-3, 3) #=> [“c”, “d”, “e”]
EOF
}
}
x.report(”""" comment") {
100000.times {
"""
#------------------------------------------------------------ Array#slice

arr.slice( anInteger ) -> anObject

arr.slice( start, length ) -> aSubArray

arr.slice( aRange ) -> aSubArray

#------------------------------------------------------------------------

Synonym for Array#[ ].

a = [ “a”, “b”, “c”, “d”, “e” ]

a.slice(2) + a.slice(0) + a.slice(1) #=> “cab”

a.slice(6) #=> nil

a.slice(1, 2) #=> [“b”, “c”]

a.slice(1…3) #=> [“b”, “c”, “d”]

a.slice(4…7) #=> [“e”]

a.slice(6…10) #=> nil

a.slice(-3, 3) #=> [“c”, “d”, “e”]

"""
}

}
}


sdmitry -=- Dmitry V. Sabanin
MuraveyLabs.

Hi,

···

At Mon, 16 Jun 2003 23:49:53 +0900, Hal E. Fulton hal9000@hypermetrics.com wrote:

I don’t think it’s a major architectural problem;
more that Matz has not seen a significant need
for multiline comments. It has been discussed
some.

The only time I miss them is when I (rarely)
want to put a comment in the middle of a line.

The first reason is the notation. At least, (* ) and / */
conflicted or didn’t match with Ruby’s syntax. Do you have any
idea?


Nobu Nakada

I think, to do this, you don’t even need dnl:

<<EOF
Remember
that Ruby is
expression-oriented.
EOF

Hal

···

----- Original Message -----
From: “Guillaume Marcais” guslist@free.fr
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Sent: Monday, June 16, 2003 9:51 AM
Subject: Re: Multiline comments?

def dnl(*args); nil end
dnl <<EOF
This is a
multiline comment
EOF

Might not solve really what you want though!

Guillaume.


Hal Fulton
hal9000@hypermetrics.com

The benchmark doesn’t take into account the speed hit during compilation
(which is only done once). Not that it really matters, but results could
be more meaningful if you used some evil arts (eval) :slight_smile:

···

On Wed, Jun 18, 2003 at 04:10:16AM +0900, Dmitry V. Sabanin wrote:

Here is a little benchmark for comments that were discussed here,

$ ruby1.7 comments.rb
user system total real
default comment 0.140000 0.000000 0.140000 ( 0.141877)

comment 0.140000 0.000000 0.140000 ( 0.133724)

EOF comment 0.500000 0.020000 0.520000 ( 0.633371)
“”" comment 0.520000 0.010000 0.530000 ( 0.579245)

I know that times i’m repeating code are too big for default case we use
comments in, but if it will be used i.e. in a function executed from
1…999999.each i guess runtime will be the same.

P.S. Maybe i’m totally wrong and it’s not even worth speaking about it :slight_smile:


_ _

__ __ | | ___ _ __ ___ __ _ _ __
'_ \ / | __/ __| '_ _ \ / ` | ’ \
) | (| | |
__ \ | | | | | (| | | | |
.__/ _,
|_|/| || ||_,|| |_|
Running Debian GNU/Linux Sid (unstable)
batsman dot geo at yahoo dot com

Do you mean to say that I can read mail with vi too? :wink:
Didn’t you know that?
:r /var/spool/mail/jk
– debian-mentors

I’ve augmented the code with two more tests and these are the results:

07:28:06 [temp]: ruby comments.rb
user system total real
default comment 0.047000 0.000000 0.047000 ( 0.047000)

comment 0.032000 0.000000 0.032000 ( 0.032000)

EOF comment 0.093000 0.000000 0.093000 ( 0.093000)
‘EOF’ comment 0.094000 0.000000 0.094000 ( 0.094000)
=begin comment 0.031000 0.000000 0.031000 ( 0.031000)
“”" comment 0.094000 0.000000 0.094000 ( 0.094000)
07:28:46 [temp]:

=begin =end is the fastest for multiline comments with # style being only
a bit slower.

Regards

robert

comments.rb (4.56 KB)

Hi,

I don’t think it’s a major architectural problem;
more that Matz has not seen a significant need
for multiline comments. It has been discussed
some.

The only time I miss them is when I (rarely)
want to put a comment in the middle of a line.

The first reason is the notation. At least, (* ) and / */
conflicted or didn’t match with Ruby’s syntax. Do you have any
idea?

Not to say that /* … / matches Ruby’s syntax very well, but it doesn’t
really conflict, does it? You can’t start a regex with /
because the
kleene star is not referencing anything.

Wes

···

At Mon, 16 Jun 2003 23:49:53 +0900, > Hal E. Fulton hal9000@hypermetrics.com wrote:

I would prefer a ‘#’ instead of ‘*’ to emphasize its reliation to the
existing comment statement. Either of the candidates below feel quite
natural to me:

(#
This is a
multiline comment
#)

{#
This is a
multiline comment
#}

[#
This is a
multiline comment
#]

/#
This is a
multiline comment
#/

···

nobu.nokada@softhome.net wrote:

Hi,

At Mon, 16 Jun 2003 23:49:53 +0900, > Hal E. Fulton hal9000@hypermetrics.com wrote:

I don’t think it’s a major architectural problem;
more that Matz has not seen a significant need
for multiline comments. It has been discussed
some.

The only time I miss them is when I (rarely)
want to put a comment in the middle of a line.

The first reason is the notation. At least, (* ) and / */
conflicted or didn’t match with Ruby’s syntax. Do you have any
idea?

I think I would use something based on #, but
looking like array syntax %w[…] or string
syntax %[…]

Perhaps #(…) or even #{…} (though the latter
would mean no comments inside interpolated expressions).

Hal

···

----- Original Message -----
From: nobu.nokada@softhome.net
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Sent: Monday, June 16, 2003 10:26 AM
Subject: Re: Multiline comments?

Hi,

At Mon, 16 Jun 2003 23:49:53 +0900, > Hal E. Fulton hal9000@hypermetrics.com wrote:

I don’t think it’s a major architectural problem;
more that Matz has not seen a significant need
for multiline comments. It has been discussed
some.

The only time I miss them is when I (rarely)
want to put a comment in the middle of a line.

The first reason is the notation. At least, (* ) and / */
conflicted or didn’t match with Ruby’s syntax. Do you have any
idea?

Hal E. Fulton wrote:

I think, to do this, you don’t even need dnl:

<<EOF
Remember
that Ruby is
expression-oriented.
EOF

Or, for the Python fans, Ruby supports

“”“Remember that
Ruby is expression-oriented
(and has implicit string concatenation…”“”

Of course, it isn’t too good having any of these in a oft-repeated loop,
and mine won’t be too happy if the comment contains a ‘"’.

But then again, given a decent editor, I’m not sure I’ve ever felt the
need for multi-line comments in Ruby. Given an editor that understands
word-wrap in comment mode, I much prefer having an explicit comment
character at the start of each line; it seems to make scanning the file
easier.

Cheers

Dave

I used to use this until I saw another post which
pointed out that Ruby string-interpolates inside
here-docs :frowning:
… or :slight_smile: ?

puts ‘AA’

<<CMT
puts ‘BB’, #{puts ‘Oops’}
CMT

puts ‘CC’

#-> AA
#-> Oops
#-> CC

(And it’s not always so obvious what has executed)

Recommend .never. to use this for m-l-comments.

daz

···

“Hal E. Fulton” hal9000@hypermetrics.com wrote:

<<EOF
Remember
that Ruby is
expression-oriented.
EOF

Hal


Hal Fulton
hal9000@hypermetrics.com

“Hal E. Fulton” hal9000@hypermetrics.com schrieb im Newsbeitrag
news:002901c33421$ce01dea0$0300a8c0@austin.rr.com

From: “Guillaume Marcais” guslist@free.fr
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Sent: Monday, June 16, 2003 9:51 AM
Subject: Re: Multiline comments?

def dnl(*args); nil end
dnl <<EOF
This is a
multiline comment
EOF

Might not solve really what you want though!

Guillaume.

I think, to do this, you don’t even need dnl:

<<EOF
Remember
that Ruby is
expression-oriented.
EOF

Better use <<‘EOF’ to avoid any evaluations inside of the comment.

And one can do

=begin

This is also regarded
a
multiline
comment

=end

:slight_smile:

robert
···

----- Original Message -----

Hi,

···

nobu.nokada@softhome.net wrote:

The first reason is the notation. At least, (* ) and / */
conflicted or didn’t match with Ruby’s syntax. Do you have any
idea?

At first thought I couldn’t think of anything that would conflict with

<<< comment >>>

or

← comment →

Bernhard

Hal E. Fulton wrote:

I think, to do this, you don’t even need dnl:

<<EOF
Remember
that Ruby is
expression-oriented.
EOF

Or, for the Python fans, Ruby supports

“”“Remember that
Ruby is expression-oriented
(and has implicit string concatenation…”“”

Of course, it isn’t too good having any of these in a oft-repeated loop,
and mine won’t be too happy if the comment contains a ‘"’.

But then again, given a decent editor, I’m not sure I’ve ever felt the
need for multi-line comments in Ruby. Given an editor that understands
word-wrap in comment mode, I much prefer having an explicit comment
character at the start of each line; it seems to make scanning the file
easier.

/* Which is often what

  • people do
  • in C/C++ anyhow
    */

I guess the need of multi-line comment could be to comment out quickly a
chunk of code. And Emacs doesn’t have a “comment out region” like in
c-mode. Does anybody know how to add that feature? What about other
editors?

Guillaume.

···

On Mon, 2003-06-16 at 12:30, Dave Thomas wrote:

Cheers

Dave

Dave Thomas wrote:

Hal E. Fulton wrote:

I think, to do this, you don’t even need dnl:

<<EOF
Remember
that Ruby is
expression-oriented.
EOF

Or, for the Python fans, Ruby supports

“”“Remember that
Ruby is expression-oriented
(and has implicit string concatenation…”“”

And in the same vein:

puts; %{ this is a comment }; puts

Just don’t leave out the semicolons! As Hal pointed out, this “comment”
is an expression with a value, not something filtered out by the
preprocessor.

I used to use this until I saw another post which
pointed out that Ruby string-interpolates inside
here-docs :frowning:
… or :slight_smile: ?

puts ‘AA’

<<CMT
puts ‘BB’, #{puts ‘Oops’}
CMT

puts ‘CC’

#-> AA
#-> Oops
#-> CC

(And it’s not always so obvious what has executed)

Recommend .never. to use this for m-l-comments.

Good point… but there’s always

<<‘EOF’
I will not
interpolate: #{destroy_world()}
EOF

Hal

···

----- Original Message -----
From: “daz” dooby@d10.karoo.co.uk
Newsgroups: comp.lang.ruby
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Sent: Monday, June 16, 2003 5:18 PM
Subject: Re: Multiline comments?