Comment blocks like rem..endrem

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
EdzUp
User
User
Posts: 30
Joined: Fri Aug 17, 2007 12:10 am
Location: Worthing, UK

Comment blocks like rem..endrem

Post by EdzUp »

I would like comment blocks to be added to PB yeah you have the select and adjust system but it would be more elegant if you could just call something like
rem
this is a comment line
so is this
endrem

this line is code though

Its only a small example BUT imagine if you have a hundred line piece of code you wish to change just a quick rem..endrem would work wonders or some command similar :) I do prefer C's /*...*/ but thats another story :)
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: Comment blocks like rem..endrem

Post by davido »

Hi Edzup,

You can comment a range already by simply highlighting it and pressing control-B.

To un-comment it just highlight it and use alt-B

The same commands are in the right-click menu.

Regards

Dave
DE AA EB
User avatar
glomph
User
User
Posts: 48
Joined: Tue Apr 27, 2010 1:43 am
Location: St. Elsewhere / Germany
Contact:

Re: Comment blocks like rem..endrem

Post by glomph »

Hi,
you could use Compiler If .... and Compilerendif with something you dont use.


glomph
User avatar
skywalk
Addict
Addict
Posts: 4211
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Comment blocks like rem..endrem

Post by skywalk »

Code: Select all

CompilerIf 0
  This is 1 line of a block comment...
  And so is this but you have To deal With autoformatting. :(
CompilerEndIf
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
MachineCode
Addict
Addict
Posts: 1482
Joined: Tue Feb 22, 2011 1:16 pm

Re: Comment blocks like rem..endrem

Post by MachineCode »

CompilerIf works, but the comments are formatted incorrectly (as skywalk said), and the commented block is not in the IDE's comment color. So, it's not really a good solution.
Microsoft Visual Basic only lasted 7 short years: 1991 to 1998.
PureBasic: Born in 1998 and still going strong to this very day!
User avatar
Tenaja
Addict
Addict
Posts: 1959
Joined: Tue Nov 09, 2010 10:15 pm

Re: Comment blocks like rem..endrem

Post by Tenaja »

MachineCode wrote:CompilerIf works, but the comments are formatted incorrectly (as skywalk said), and the commented block is not in the IDE's comment color. So, it's not really a good solution.
+1
LuCiFeR[SD]
666
666
Posts: 1033
Joined: Mon Sep 01, 2003 2:33 pm

Re: Comment blocks like rem..endrem

Post by LuCiFeR[SD] »

+1 on the original request. I think Rem... EndRem blocks would be very useful
User avatar
Shield
Addict
Addict
Posts: 1021
Joined: Fri Jan 21, 2011 8:25 am
Location: 'stralia!
Contact:

Re: Comment blocks like rem..endrem

Post by Shield »

Nothing against block comments, but please not with rem / endrem... :?
Then again they are not needed anyway. (At least myself, I never use them in any language to comment something).
Image
Blog: Why Does It Suck? (http://whydoesitsuck.com/)
"You can disagree with me as much as you want, but during this talk, by definition, anybody who disagrees is stupid and ugly."
- Linus Torvalds
User avatar
Tenaja
Addict
Addict
Posts: 1959
Joined: Tue Nov 09, 2010 10:15 pm

Re: Comment blocks like rem..endrem

Post by Tenaja »

Shield wrote:Nothing against block comments, but please not with rem / endrem... :?
Then again they are not needed anyway. (At least myself, I never use them in any language to comment something).
Block comments are perfect for commenting out an entire procedure or set of procedures, so you can try alternates without losing the original.

I agree; Rem EndRem are not good, but something more "pb-like" would be CommentStart/End. (Although I would much rather type /* */, because it is shorter and common vernacular.
jassing
Addict
Addict
Posts: 1885
Joined: Wed Feb 17, 2010 12:00 am

Re: Comment blocks like rem..endrem

Post by jassing »

Tenaja wrote: I agree; Rem EndRem are not good, but something more "pb-like" would be CommentStart/End. (Although I would much rather type /* */, because it is shorter and common vernacular.
+1 on this -- but I'd make it more "purebasic-ish"

Code: Select all

; This is a single line comment

;{
  this is a multiline
  comment
;}
User avatar
Shield
Addict
Addict
Posts: 1021
Joined: Fri Jan 21, 2011 8:25 am
Location: 'stralia!
Contact:

Re: Comment blocks like rem..endrem

Post by Shield »

Tenaja wrote: Block comments are perfect for commenting out an entire procedure or set of procedures...
Yes, but only for that. If they are actively used to actually comment the source they are nothing
more than a huge pain in the rear if they are not nestable.
Image
Blog: Why Does It Suck? (http://whydoesitsuck.com/)
"You can disagree with me as much as you want, but during this talk, by definition, anybody who disagrees is stupid and ugly."
- Linus Torvalds
MachineCode
Addict
Addict
Posts: 1482
Joined: Tue Feb 22, 2011 1:16 pm

Re: Comment blocks like rem..endrem

Post by MachineCode »

Tenaja wrote:Block comments are perfect for commenting out an entire procedure or set of procedures, so you can try alternates without losing the original.
What? If you comment out a procedure, then you also need to comment out all calls to that procedure; otherwise you'll get an error when trying to compile.
Microsoft Visual Basic only lasted 7 short years: 1991 to 1998.
PureBasic: Born in 1998 and still going strong to this very day!
User avatar
Shield
Addict
Addict
Posts: 1021
Joined: Fri Jan 21, 2011 8:25 am
Location: 'stralia!
Contact:

Re: Comment blocks like rem..endrem

Post by Shield »

Not if he replaces the procedure by an alternative, as he said (same name, probably directly below the old procedure).
The problem with block comments is, if they are implemented as in C#, C++, Java, ... that they are not nestable,
which means commenting out block comments, e.g.

Code: Select all

/*
blah
/*
old blah
*/
*/
is not possible without removing the previous */. So please...make them nestable. :)
Image
Blog: Why Does It Suck? (http://whydoesitsuck.com/)
"You can disagree with me as much as you want, but during this talk, by definition, anybody who disagrees is stupid and ugly."
- Linus Torvalds
MachineCode
Addict
Addict
Posts: 1482
Joined: Tue Feb 22, 2011 1:16 pm

Re: Comment blocks like rem..endrem

Post by MachineCode »

Shield wrote:Not if he replaces the procedure by an alternative, as he said (same name, probably directly below the old procedure).
Oh, I see. In that case, it's easier to just rename the old procedure instead, rather than commenting it all out. Just add an extra single char to the start of the procedure name, to make it redundant.
Microsoft Visual Basic only lasted 7 short years: 1991 to 1998.
PureBasic: Born in 1998 and still going strong to this very day!
User avatar
Tenaja
Addict
Addict
Posts: 1959
Joined: Tue Nov 09, 2010 10:15 pm

Re: Comment blocks like rem..endrem

Post by Tenaja »

Shield wrote:Not if he replaces the procedure by an alternative, as he said (same name, probably directly below the old procedure).
The problem with block comments is, if they are implemented as in C#, C++, Java, ... that they are not nestable,
which means commenting out block comments, e.g.

Code: Select all

/*
blah
/*
old blah
*/
*/
is not possible without removing the previous */. So please...make them nestable. :)
Actually, using the characters of C and Java do NOT mean it is not nestable. The ability to nest block comments is entirely up to the compiler author. It is actually quite easy to "upgrade" block comments to allow nesting, no matter WHAT character set you use to start it. This text below shows how to do it very easily with one-character, but with two or more characters, it is trivially different:
There's one last item to deal with: nested comments. Some programmers like the idea of nesting comments, since it allows you to comment out code during debugging. The code I've given here won't allow that and, again, neither will Turbo Pascal.

But the fix is incredibly easy. All we need to do is to make SkipComment recursive:

Code: Select all

{ Skip a comment field }
procedure SkipComment;
begin
  while Look <> '}' do 
    begin
      GetChar;
      if Look = '{' then
        SkipComment;
     end;
  GetChar;
end;       


That does it. As sophisticated a comment-handler as you'll ever need.
Post Reply