Block comment?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

Block comment?

Christian Hoffmann-3
I consider it quite worth while to introduce into R syntax a nestable
block comment like

#{
<block of code>
}#

It would make documentation more easily manageable and lucid.
Is there considerable need for this.

Please, comment on this.
How about R core?

Christian
--
Christian Hoffmann
Rigiblickstrasse 15b
CH-8915 Hausen am Albis
Switzerland
Telefon +41-(0)44-7640853

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Block comment?

Uwe Ligges-3


On 02.09.2017 11:40, Christian wrote:
> I consider it quite worth while to introduce into R syntax a nestable
> block comment like
>
> #{
> <block of code>
> }#

if(FALSE){
<block of code>
}

Best,
Uwe Ligges


> It would make documentation more easily manageable and lucid.
> Is there considerable need for this.
>
> Please, comment on this.
> How about R core?
>
> Christian

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Block comment?

Suzen, Mehmet
AFAIK block comment is not possible
it needs to be implemented in R interpreter and defined in the
parser.'If' solution is not elegant.

On 2 September 2017 at 14:09, Uwe Ligges
<[hidden email]> wrote:

>
>
> On 02.09.2017 11:40, Christian wrote:
>>
>> I consider it quite worth while to introduce into R syntax a nestable
>> block comment like
>>
>> #{
>> <block of code>
>> }#
>
>
> if(FALSE){
> <block of code>
> }
>
> Best,
> Uwe Ligges
>
>
>> It would make documentation more easily manageable and lucid.
>> Is there considerable need for this.
>>
>> Please, comment on this.
>> How about R core?
>>
>> Christian
>
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Block comment?

Bert Gunter-2
Uwe showed an R code -ish way to do it. RStudio and probably other R UI's
and IDE's -- which is the way most folks write code, I think -- also make
it easy to do.

Cheers,
Bert




Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )

On Sat, Sep 2, 2017 at 7:54 AM, Suzen, Mehmet <[hidden email]> wrote:

> AFAIK block comment is not possible
> it needs to be implemented in R interpreter and defined in the
> parser.'If' solution is not elegant.
>
> On 2 September 2017 at 14:09, Uwe Ligges
> <[hidden email]> wrote:
> >
> >
> > On 02.09.2017 11:40, Christian wrote:
> >>
> >> I consider it quite worth while to introduce into R syntax a nestable
> >> block comment like
> >>
> >> #{
> >> <block of code>
> >> }#
> >
> >
> > if(FALSE){
> > <block of code>
> > }
> >
> > Best,
> > Uwe Ligges
> >
> >
> >> It would make documentation more easily manageable and lucid.
> >> Is there considerable need for this.
> >>
> >> Please, comment on this.
> >> How about R core?
> >>
> >> Christian
> >
> >
> > ______________________________________________
> > [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide http://www.R-project.org/
> posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/
> posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Block comment?

Jeff Newmiller
In reply to this post by Suzen, Mehmet
I agree, since one reason for block commenting is to include syntactically-invalid information (such as broken code) in the source code.

However, block commenting is not wholly a good thing, as both the R parser and human coders often find it challenging to identify where the end of the block is, making it difficult to tell whether you are looking at live code or comments.  A good editor can add/remove comment marks to "blocks" of lines of code, relieving the programmer of tedium while maintaining clarity about which lines are active or not.

Block commenting is also a bit of a cultural thing, like using or avoiding tab characters in code, or vi-vs-emacs... it is hard to change people's minds about it, and potentially inflammatory to try. I think it is safe to say that the designers of R were aware of block commenting and consciously chose to not include it in the language.
--
Sent from my phone. Please excuse my brevity.

On September 2, 2017 7:54:18 AM PDT, "Suzen, Mehmet" <[hidden email]> wrote:

>AFAIK block comment is not possible
>it needs to be implemented in R interpreter and defined in the
>parser.'If' solution is not elegant.
>
>On 2 September 2017 at 14:09, Uwe Ligges
><[hidden email]> wrote:
>>
>>
>> On 02.09.2017 11:40, Christian wrote:
>>>
>>> I consider it quite worth while to introduce into R syntax a
>nestable
>>> block comment like
>>>
>>> #{
>>> <block of code>
>>> }#
>>
>>
>> if(FALSE){
>> <block of code>
>> }
>>
>> Best,
>> Uwe Ligges
>>
>>
>>> It would make documentation more easily manageable and lucid.
>>> Is there considerable need for this.
>>>
>>> Please, comment on this.
>>> How about R core?
>>>
>>> Christian
>>
>>
>> ______________________________________________
>> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>
>______________________________________________
>[hidden email] mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide
>http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Block comment?

R help mailing list-2
In reply to this post by Suzen, Mehmet
Is the reason you want a block comment containing code (as opposed to
arbitrary text) that you want to be able to easily run the commented out
code?  If so the 'if()' construct has the advantage that you only need to
change code at the start of the comment, not at both ends.

The if(FALSE) could be if(isTRUE(getOption("DEBUG_ISSUE_XYZ"))) so you
would not even have to change code to re-enable the debugging code, just
call options(DEBUG_ISSUE_XYX=TRUE)).


Bill Dunlap
TIBCO Software
wdunlap tibco.com

On Sat, Sep 2, 2017 at 7:54 AM, Suzen, Mehmet <[hidden email]> wrote:

> AFAIK block comment is not possible
> it needs to be implemented in R interpreter and defined in the
> parser.'If' solution is not elegant.
>
> On 2 September 2017 at 14:09, Uwe Ligges
> <[hidden email]> wrote:
> >
> >
> > On 02.09.2017 11:40, Christian wrote:
> >>
> >> I consider it quite worth while to introduce into R syntax a nestable
> >> block comment like
> >>
> >> #{
> >> <block of code>
> >> }#
> >
> >
> > if(FALSE){
> > <block of code>
> > }
> >
> > Best,
> > Uwe Ligges
> >
> >
> >> It would make documentation more easily manageable and lucid.
> >> Is there considerable need for this.
> >>
> >> Please, comment on this.
> >> How about R core?
> >>
> >> Christian
> >
> >
> > ______________________________________________
> > [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide http://www.R-project.org/
> posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/
> posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: [FORGED] Re: Block comment?

Rolf Turner
On 03/09/17 03:56, William Dunlap via R-help wrote:
> Is the reason you want a block comment containing code (as opposed to
> arbitrary text) that you want to be able to easily run the commented out
> code?  If so the 'if()' construct has the advantage that you only need to
> change code at the start of the comment, not at both ends.
>
> The if(FALSE) could be if(isTRUE(getOption("DEBUG_ISSUE_XYZ"))) so you
> would not even have to change code to re-enable the debugging code, just
> call options(DEBUG_ISSUE_XYX=TRUE)).


(a) The foregoing is getting too subtle for my feeble brain.

(b) A fundamental problem with the

    if(FALSE) {
       ...
    }

paradigm is that the enclosed code must be syntactically valid, and
there are certainly situations in which one might wish to comment out
sections of code that are *not* syntactically valid.  E.g. one might
wish to comment out *part* of a piece of syntactically valid code for
the purpose of experimenting with an alternative approach.

cheers,

Rolf

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

> On Sat, Sep 2, 2017 at 7:54 AM, Suzen, Mehmet <[hidden email]> wrote:
>
>> AFAIK block comment is not possible
>> it needs to be implemented in R interpreter and defined in the
>> parser.'If' solution is not elegant.
>>
>> On 2 September 2017 at 14:09, Uwe Ligges
>> <[hidden email]> wrote:
>>>
>>>
>>> On 02.09.2017 11:40, Christian wrote:
>>>>
>>>> I consider it quite worth while to introduce into R syntax a nestable
>>>> block comment like
>>>>
>>>> #{
>>>> <block of code>
>>>> }#
>>>
>>>
>>> if(FALSE){
>>> <block of code>
>>> }
>>>
>>> Best,
>>> Uwe Ligges
>>>
>>>
>>>> It would make documentation more easily manageable and lucid.
>>>> Is there considerable need for this.
>>>>
>>>> Please, comment on this.
>>>> How about R core?
>>>>
>>>> Christian
>>>
>>>
>>> ______________________________________________
>>> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide http://www.R-project.org/
>> posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>
>> ______________________________________________
>> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/
>> posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: [FORGED] Re: Block comment?

Duncan Murdoch-2
On 02/09/2017 6:57 PM, Rolf Turner wrote:

> On 03/09/17 03:56, William Dunlap via R-help wrote:
>> Is the reason you want a block comment containing code (as opposed to
>> arbitrary text) that you want to be able to easily run the commented out
>> code?  If so the 'if()' construct has the advantage that you only need to
>> change code at the start of the comment, not at both ends.
>>
>> The if(FALSE) could be if(isTRUE(getOption("DEBUG_ISSUE_XYZ"))) so you
>> would not even have to change code to re-enable the debugging code, just
>> call options(DEBUG_ISSUE_XYX=TRUE)).
>
>
> (a) The foregoing is getting too subtle for my feeble brain.
>
> (b) A fundamental problem with the
>
>      if(FALSE) {
>         ...
>      }
>
> paradigm is that the enclosed code must be syntactically valid, and
> there are certainly situations in which one might wish to comment out
> sections of code that are *not* syntactically valid.  E.g. one might
> wish to comment out *part* of a piece of syntactically valid code for
> the purpose of experimenting with an alternative approach.

If the code is not syntactically valid, why would you expect the block
comment to be syntactically valid?  The proposal at the start of this
thread was that #{ would open the block and would be matched by }# to
close the block.  What if the closing sequence occurred within the block
unintentionally?  Then the poor feeble programmer would be even more
confused.

I like the current rule:  any line starting with # is a comment.
(Actually the rule is a bit more subtle than that, but it's close.)
If I want to comment out a block, I can spend a long time typing # at
the start of every line, or I can ask my editor to do it.  I don't need
to worry if something in the block unintentionally closes it, because
that's impossible.  If the first line is a comment, all the rest are too.

Duncan Murdoch

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: [FORGED] Re: Block comment?

Rolf Turner

On 03/09/17 12:29, Duncan Murdoch wrote:

> On 02/09/2017 6:57 PM, Rolf Turner wrote:
>> On 03/09/17 03:56, William Dunlap via R-help wrote:
>>> Is the reason you want a block comment containing code (as opposed to
>>> arbitrary text) that you want to be able to easily run the commented out
>>> code?  If so the 'if()' construct has the advantage that you only
>>> need to
>>> change code at the start of the comment, not at both ends.
>>>
>>> The if(FALSE) could be if(isTRUE(getOption("DEBUG_ISSUE_XYZ"))) so you
>>> would not even have to change code to re-enable the debugging code, just
>>> call options(DEBUG_ISSUE_XYX=TRUE)).
>>
>>
>> (a) The foregoing is getting too subtle for my feeble brain.
>>
>> (b) A fundamental problem with the
>>
>>      if(FALSE) {
>>         ...
>>      }
>>
>> paradigm is that the enclosed code must be syntactically valid, and
>> there are certainly situations in which one might wish to comment out
>> sections of code that are *not* syntactically valid.  E.g. one might
>> wish to comment out *part* of a piece of syntactically valid code for
>> the purpose of experimenting with an alternative approach.
>
> If the code is not syntactically valid, why would you expect the block
> comment to be syntactically valid?

I thought I had made that clear.  One might wish to comment out a
*piece* of syntactically valid code (with a view to replacing it).
The piece commented out might not be syntactically valid simply because
it is *just a piece* and might thereby be incomplete.

> The proposal at the start of this
> thread was that #{ would open the block and would be matched by }# to
> close the block.  What if the closing sequence occurred within the block
> unintentionally?  Then the poor feeble programmer would be even more
> confused.

Do not the same considerations essentially apply to the well established
/* .... */ convention used in C?  Well maybe you simply *can't* get the
"*/" string within a block of C code, but still ....

If "#{....}#" runs this risk, then some other construction which doesn't
run the risk could be used.

> I like the current rule:

De gustibus non disputandum.

> any line starting with # is a comment.
> (Actually the rule is a bit more subtle than that, but it's close.)
> If I want to comment out a block, I can spend a long time typing # at
> the start of every line, or I can ask my editor to do it.  I don't need
> to worry if something in the block unintentionally closes it, because
> that's impossible.  If the first line is a comment, all the rest are too.

I don't follow the foregoing, but no matter.  I'm slow.

This issue is quite obviously No Big Deal.  Block comments are a
convenience that it would be nice to have, but obviously one can live
without them and not suffer unduly.

cheers,

Rolf

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: [FORGED] Re: Block comment?

Duncan Murdoch-2
On 03/09/2017 12:49 AM, Rolf Turner wrote:

>
> On 03/09/17 12:29, Duncan Murdoch wrote:
>
>> On 02/09/2017 6:57 PM, Rolf Turner wrote:
>>> On 03/09/17 03:56, William Dunlap via R-help wrote:
>>>> Is the reason you want a block comment containing code (as opposed to
>>>> arbitrary text) that you want to be able to easily run the commented out
>>>> code?  If so the 'if()' construct has the advantage that you only
>>>> need to
>>>> change code at the start of the comment, not at both ends.
>>>>
>>>> The if(FALSE) could be if(isTRUE(getOption("DEBUG_ISSUE_XYZ"))) so you
>>>> would not even have to change code to re-enable the debugging code, just
>>>> call options(DEBUG_ISSUE_XYX=TRUE)).
>>>
>>>
>>> (a) The foregoing is getting too subtle for my feeble brain.
>>>
>>> (b) A fundamental problem with the
>>>
>>>       if(FALSE) {
>>>          ...
>>>       }
>>>
>>> paradigm is that the enclosed code must be syntactically valid, and
>>> there are certainly situations in which one might wish to comment out
>>> sections of code that are *not* syntactically valid.  E.g. one might
>>> wish to comment out *part* of a piece of syntactically valid code for
>>> the purpose of experimenting with an alternative approach.
>>
>> If the code is not syntactically valid, why would you expect the block
>> comment to be syntactically valid?
>
> I thought I had made that clear.  One might wish to comment out a
> *piece* of syntactically valid code (with a view to replacing it).
> The piece commented out might not be syntactically valid simply because
> it is *just a piece* and might thereby be incomplete.
>
>> The proposal at the start of this
>> thread was that #{ would open the block and would be matched by }# to
>> close the block.  What if the closing sequence occurred within the block
>> unintentionally?  Then the poor feeble programmer would be even more
>> confused.
>
> Do not the same considerations essentially apply to the well established
> /* .... */ convention used in C?  Well maybe you simply *can't* get the
> "*/" string within a block of C code, but still ....

Those aren't nestable.  You can have as many opening /* sequences as you
like, and the first */ will close the comment.  The usual recommendation
for nestable comments in C++ is to use #if 0 ... #endif, a lot like
Uwe's suggestion.  (Since this is a preprocessor command, what falls
between the markers doesn't need to be legal C++, but it does need to be
legal preprocessor markup.)

>
> If "#{....}#" runs this risk, then some other construction which doesn't
> run the risk could be used.
>
>> I like the current rule:
>
> De gustibus non disputandum.
>
>> any line starting with # is a comment.
>> (Actually the rule is a bit more subtle than that, but it's close.)
>> If I want to comment out a block, I can spend a long time typing # at
>> the start of every line, or I can ask my editor to do it.  I don't need
>> to worry if something in the block unintentionally closes it, because
>> that's impossible.  If the first line is a comment, all the rest are too.
>
> I don't follow the foregoing, but no matter.  I'm slow.

A shorter version:  just put # at the start of every line in the block.
That's nestable, but if you mess up the nesting, it's still completely
obvious what is commented out and what is not.

Duncan Murdoch

>
> This issue is quite obviously No Big Deal.  Block comments are a
> convenience that it would be nice to have, but obviously one can live
> without them and not suffer unduly.
>
> cheers,
>
> Rolf
>

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: [FORGED] Re: Block comment?

S Ellison-2
In reply to this post by Rolf Turner
> Do not the same considerations essentially apply to the well established
> /* .... */ convention used in C?  Well maybe you simply *can't* get the "*/"
> string within a block of C code, but still ....
Yes, the same problem arises in C. And you _can_ get */ in valid code - as the closing part of a comment. Attempts to nest C block comments result in part of the outer block becoming uncommented and the outer block comment terminator becoming invalid syntax.

For example
main() {
 /*
    /* Hello world */   <- now the comment terminator
         printf("hello world")
 /*  <- oops
}

Avoiding that trap is one reason that ANSI C block comments often use an extra ' *' at the beginning of each line - as in

/* **************
 * An example ANSI C  
 * heading  
 * ************** */
which rather undermines the convenience of the whole thing.

So there's probably more than one reason // was added to C. That and better editors.

S Ellison


*******************************************************************
This email and any attachments are confidential. Any use...{{dropped:8}}

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.