DAY 011: REM
#1
A command which everyone thinks they know flawlessly, and yet, they probably don't.  Tongue

What is it?  REM is a command that allows people to place remarks inside a program so that it helps clarify what's going on and makes it much easier to come back to the program at a future time and understand just what the BLEEP the programmer was thinking when he coded everything originially.

How to use it?  Just add REM to where you want to place a comment, and then type out your comment!



And with the basic description of this most basic command out of the way, let's touch back upon the opening sentence which begins this post, where I claimed: most folks don't know everything about REM, like they think they do.  WTH is up with that??  "What are people misunderstanding", you ask?

Most people think that REM and ' (the single quote) are interchangeable and completely the same.  In fact, most people think that ' (the single quote) is nothing more than a shortcut to reduce typing out the whole word REM.

This isn't true!!

REM is a *COMMAND*.

' (the single quote) is part of a *COMMENT*.

With REM, REM is an actual command which basically says, "Hey, everything past this point is a comment!"

With ' (the single quote), ' is PART of the comment itself, and is basically excluded from your code.

A subtle difference, but one which can have drastic effects upon a program.  Let's take the following code for example:

Code: (Select All)
IF foo THEN REM foo is a make-believe variable for my example!

Code: (Select All)
IF foo THEN 'foo is a make-believe variable for my example!

Now, at first glance, those two statements look *exactly* alike.  They're not.  Tongue

The first code box contains a single-line IF statement, whereas the second code box contains the start of a multi-line IF statement.  You're going to have to put an END IF in the second code box, or else run into all sorts of errors in your code.

WHY??

Because you ended the first IF statement with a command.  Sure, it's a command which says, "A comment is coming next," but it's still a command.  Think of it just like you would:  IF foo THEN PRINT.   That command (REM, in this case) is enough to close up that IF statement and make it a valid single-line statement.

On the other hand, the second segment of code is basically just IF foo THEN....  Then WHAT??  You're not telling that IF statement what to do on that line, so it's got to be a multi-line IF statement.

REM is a *COMMAND*, just like GOTO, PRINT, and all the other commands in the language.  It's just a command which says, "Comments to the right!"

' (the single quote) is an actual part of a comment, and is basically ignored when used as one inside your programs.  It's not a command, and that's the biggest difference -- and it's a significant one -- between the two.
Reply
#2
I think you want to call ' (single quote or maybe apostrophe though it's not the curved one). It's certainly not a colon.

I never use REM (too much typing and ' seems neater), if I did it would be only to start a line with a comment. It's in same old pile as Let and Option Base.
b = b + ...
Reply
#3
(11-16-2022, 05:25 PM)bplus Wrote: I think you want to call ' (single quote or maybe apostrophe though it's not the curved one). It's certainly not a colon.

It's certainly not!  LOL!

Chalk that one up to lack of coffee in the brain, or some such.  Who knows why in the heck I was calling a ', a :, but...

...had to be lack of coffee in the brain.  Tongue
Reply
#4
(11-16-2022, 04:43 PM)SMcNeill Wrote: ...snip...

I love this article.

I had never thought about it: REM is a statement.

I knew it subconsciously via the pain using it at the end of a line after code because of the needed separator (":").

But I had never thought about it in the use of an IF ... THEN REM scenario.  And I like it.  I can see times in which I'd want to make a "do nothing in this condition" very explicit, and I like this approach.  Totally floats my boat.

(Well, a "DO_NADA" statement would be more semantically jugular-grabbing, but REM is good enough.)

Thanks !
Reply
#5
(11-16-2022, 04:43 PM)SMcNeill Wrote: Most people think that REM and ' (the single quote) are interchangeable and completely the same.  In fact, most people think that ' (the single quote) is nothing more than a shortcut to reduce typing out the whole word REM.

This isn't true!!

REM is a *COMMAND*.

' (the single quote) is part of a *COMMENT*.

With REM, REM is an actual command which basically says, "Hey, everything past this point is a comment!"

With ' (the single quote), ' is PART of the comment itself, and is basically excluded from your code.

A subtle difference, but one which can have drastic effects upon a program.  Let's take the following code for example:

Code: (Select All)
IF foo THEN REM foo is a make-believe variable for my example!

Code: (Select All)
IF foo THEN 'foo is a make-believe variable for my example!

Now, at first glance, those two statements look *exactly* alike.  They're not.  Tongue

The first code box contains a single-line IF statement, whereas the second code box contains the start of a multi-line IF statement.  You're going to have to put an END IF in the second code box, or else run into all sorts of errors in your code.

WHY??

Because you ended the first IF statement with a command.  Sure, it's a command which says, "A comment is coming next," but it's still a command.  Think of it just like you would:  IF foo THEN PRINT.   That command (REM, in this case) is enough to close up that IF statement and make it a valid single-line statement.
Your wisdom about the BASIC programming language seems to have no end, I'm surprised half the time or more that you get up to correct other people and help to clear misunderstandings. Previously I didn't care about "REM" except in MS-DOS batch scripts, LOL cannot use anything else in place of that keyword. Now this must be a reason why you proposed the "_NOREM" on Github!

I have to be reeled in so I put comments into my code to share with other people. Also I picked up the "double-apostrophe" from somewhere, it should have been three of them from a few Python code snippets with luxurious documentation.

Wait does this mean you guys will finally edit the QuickBASIC metacommands like $INCLUDE so we don't have to put an apostrophe at front any longer?
Reply
#6
(11-16-2022, 06:04 PM)CharlieJV Wrote:
(11-16-2022, 04:43 PM)SMcNeill Wrote: ...snip...

I love this article.

I had never thought about it: REM is a statement.

I knew it subconsciously via the pain using it at the end of a line after code because of the needed separator (":").

But I had never thought about it in the use of an IF ... THEN REM scenario.  And I like it.  I can see times in which I'd want to make a "do nothing in this condition" very explicit, and I like this approach.  Totally floats my boat.

(Well, a "DO_NADA" statement would be more semantically jugular-grabbing, but REM is good enough.)

Thanks !

Glad to see people reading these and learning from them.  Wink

That last line of yours made me laugh out loud -- at myself!   Believe it, or not, you'll find the following in a good bit of my personal code:

Code: (Select All)
SUB DoNothingAtAll
END SUB

The main reason I tend to have such a sub in a ton of my code??  For use with _RESIZE.

_RESIZE returns a value for us so we can make adjustments in our program when the user changes the size of the window.  Only problem is, it reports ALL changes to the window size.   QB64 tends to start, by default, with a SCREEN 0 text screen.  So, naturally, once we place a statement like SCREEN _NEWIMAGE(800,600,32) in our code, it has to change size, triggering that _RESIZE flag...

And so, you'll see me with a lot of this type of code in my programs:

Code: (Select All)
SCREEN _NEWIMAGE(800, 600, 32)
IF _RESIZE THEN DoNothingAtAll

It's not a DO_NADA, but it's mighty dang close!!
Reply
#7
One of few places the single quote fails is after DATA statements.

This works:

READ a, b, c, d
DATA 1, 2, 3, 4: REM Comment

This will not:

READ a, b, c, d
DATA 1, 2, 3, 4 ' Comment

The above DATA statement throw a syntax error at run-time.

To get around this I always resorted to using line labels for a brief description of multiple DATA lines like so:

    ROW01: DATA 0,0,0,0,3,3,3,3,3,3,3,3,3,3,3,3,0,0,3,3,3,3,3,3,3,3,3,3,3,3,0,0,0,0
    ROW02: DATA 0,0,0,0,3,0,0,0,0,3,0,0,0,0,0,3,0,0,3,0,0,0,0,0,3,0,0,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DATA 0,0,0,0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,0,0,0,0


However, after reading your explanation of REM it got me to thinking. I wondered if this would work:

READ a, b, c, d
DATA 1, 2, 3, 4: ' Comment

And it does. I can now fully comment each line of DATA with a more thorough explanation of the values.

Go figure.
Reply
#8
@TerryRitchie The reason for the single quote failing to work as a comment with DATA statements is that it's proper syntax FOR the data statement.

DATA I don't like cheese., I don't like rootbeer., And I don't like you babe!

The above is 3 distinct data entries. Quotes aren't required for strings with DATA (even though I've always felt that they should be), and the above holds each statement separated by the comma as being a distinct data entry.

As you've noticed: End the DATA line with a : (colon), and then you can freely make use of the single quote comment style without any issues. Wink
Reply
#9
(11-16-2022, 07:29 PM)SMcNeill Wrote: @TerryRitchie The reason for the single quote failing to work as a comment with DATA statements is that it's proper syntax FOR the data statement.

DATA I don't like cheese., I don't like rootbeer., And I don't like you babe!

The above is 3 distinct data entries.  Quotes aren't required for strings with DATA (even though I've always felt that they should be), and the above holds each statement separated by the comma as being a distinct data entry.

As you've noticed:  End the DATA line with a : (colon), and then you can freely make use of the single quote comment style without any issues.  Wink

I ran into a slight issue. If you have more than one DATA line the colon trick does not work:

READ a, b, c, d, e
DATA 1, 2, 3, 4: ' comment
DATA 5

When trying to read the value for e a syntax error is thrown. Oh well, thought I was on to something there.
Reply
#10
I always thought line labels a great way of documenting Data statements, doing double duty with Restore as comment and GOTO line.
b = b + ...
Reply




Users browsing this thread: 3 Guest(s)