This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2007-05-30 12:57:07

Mayhem
Scratcher
Registered: 2007-05-26
Posts: 1000+

REM Statements

I mentioned this in another thread but it might easily get overlooked their.

I think Scratch would benefit from a "Remark" block, similar to the REM statement found in basic programming languages.

It would be a block in a contrasting colour (yellow?) into which a short peice of text could be entered.  It could then be placed in a stack.  The REM block would have no effect at all on the executuion of the stack, but it would be used to make notes on the effects of the stack (or the section immediately below it) which would make debugging easier and make learning/re-using other peoples code much easier.

To show the difference, here is a script from my pacman game.

Without REM
--when green flag clicked
----forever
------if color c[FFFFCC] is over c[00FF00]?
--------set pen color to c[00FF00]
------if color c[FFFFCC] is over c[00CC44]?
--------set pen color to c[00CC44]
------if color c[FFFFCC] is over c[FFFF99]?
--------pen down
--------pen up
--------change Score by 1
--------play sound "pop"
------if Score mod 51 = 0
--------play sound "one1"
--------clear

With REM
--when green flag clicked
----forever
***
REMARK:  Check the background colour under the center of pacman and set the pen to match it
***
------if color c[FFFFCC] is over c[00FF00]?
--------set pen color to c[00FF00]
------if color c[FFFFCC] is over c[00CC44]?
--------set pen color to c[00CC44]
***
REMARK: if the center of pacman is over a dot, put the pen down and up to paint over it, play a sound and increase the score by 1
***
------if color c[FFFFCC] is over c[FFFF99]?
--------pen down
--------pen up
--------change Score by 1
--------play sound "pop"
***
REMARK: If all dots eaten, reset the maze.
***
------if Score mod 51 = 0
--------play sound "one1"
--------clear


Web-spinning Spider:  http://scratch.mit.edu/projects/Mayhem/18456
3D Dungeon Adventure:  http://scratch.mit.edu/projects/Mayhem/23570
Starfighter X: http://scratch.mit.edu/projects/Mayhem/21825
Wandering Knight: http://scratch.mit.edu/projects/Mayhem/28484

Offline

 

#2 2007-05-30 16:41:34

Shanesta
Scratcher
Registered: 2007-05-24
Posts: 6

Re: REM Statements

I agree 1000%, I've been wanting this for a while now!

Offline

 

#3 2007-05-30 16:50:04

kevin_karplus
Scratcher
Registered: 2007-04-27
Posts: 1000+

Re: REM Statements

Just about every programmer who learned some other language before scratch misses comment capability.

I think it is an MIT hacker ethos that disdains comments because they make code easier to read.

I'm very afraid that when they release the source code for Scratch, that it will be unreadable because they neglected to include any comments explaining their data structures.

Offline

 

#4 2007-05-31 05:03:34

sjhalasz
Scratcher
Registered: 2007-05-26
Posts: 6

Re: REM Statements

I vote for a comment capability.  It might be added to the "control" section even though it's not really a control.  I'm trying to teach this to my instructors using examples I've written but it's very difficult to talk about it without being able to name anything.  Even a short one-line comment that could be used to name things would make it much easier to discuss the code.

I use few comments in my code in other languages.  It's true that comments are usually wrong and I don't pay much attention to them when looking at other people's code.  They take up too much room too.  But you need to be able to have at least a little.

Offline

 

#5 2007-05-31 12:31:19

kevin_karplus
Scratcher
Registered: 2007-04-27
Posts: 1000+

Re: REM Statements

The most important things to comment are big blocks of code (procedures, scripts, ...) and variables.  The meaning of the values in a variable is an immense aid in debugging.

Offline

 

#6 2007-05-31 15:05:55

jsimone
Scratcher
Registered: 2007-05-20
Posts: 28

Re: REM Statements

Just yesterday I presented "An Introduction To Programming in Scratch" to 4 classes of 5th and 4th grade students.

Unfortunately, I was unable to document, via comment blocks, some of the sample projects I left them with.

Having the ability to add remarks/comments and explain WHY the code is "this way" and does "this thing" is a *necessity* for educational use of Scratch.

Thanks for listening.

Last edited by jsimone (2007-06-05 10:26:22)

Offline

 

#7 2007-05-31 19:37:23

Roberth
Scratcher
Registered: 2007-05-15
Posts: 46

Re: REM Statements

Just as an FYI, I have added something resembling comment block by combining an if bock with a say block.  It looks something like this:

if 1 = 2
  say "add your comment here"

The idea here is that if condition will never be satisfied, so the say block will never be used.  I know this isn't perfect, and can't be used for scripts on the stage, but it does allow you to add comments into parts of your code that is slightly more complex.

For a larger project I've used this method of remarks or comments, you can look at:

http://scratch.mit.edu/projects/Roberth/7030

BTW, yes, I would love to see a separate remark or comment block, but this does "work" at the moment.

Offline

 

#8 2007-05-31 20:42:17

paulmedwal
Scratcher
Registered: 2007-03-09
Posts: 100+

Re: REM Statements

you can also use

repeat 0
   say "add comment here"

its uses fewer blocks than the if block.


clutter.scratch.mit.edu Visit the Clutter site to create multi-scene stories and multi-level games with Scratch.

Offline

 

#9 2007-06-03 22:42:44

redware
Scratcher
Registered: 2007-05-21
Posts: 92

Re: REM Statements

sjhalasz wrote:

I vote for a comment capability.  It might be added to the "control" section even though it's not really a control.

For what it is worth, I agree that a comment/note could be added to the control sections rather than as a separate block.

Offline

 

#10 2007-06-05 19:20:49

rauscher
Scratcher
Registered: 2007-05-30
Posts: 16

Re: REM Statements

Comments are essential.  I'm preparing to use Scratch for some enrichment programs at a local school.  I recall my first 100-level CS course -- they told us to write one comment per line.  At that time, I thought it was excessive but for teaching (and for grading!) it will save hours of time either trying to figure out what someone else is doing or writing documentation in an alternate medium.  And adding conditions that always evaluate to false seems inefficient.

Offline

 

#11 2007-06-05 23:47:51

kevin_karplus
Scratcher
Registered: 2007-04-27
Posts: 1000+

Re: REM Statements

One comment per line is the wrong standard.  The ratio may be right, but the comments should be one per variable plus one per major block of code, and the block comments may need to be several lines long.

Offline

 

#12 2007-06-09 13:13:16

rupert
Scratcher
Registered: 2007-06-09
Posts: 2

Re: REM Statements

I can't beleve that they don't have comments.  How can I document what I am trying to do without comments???!

This is the first thing I went looking for and could not find.

Apart from that I like Scratch, my 9 year old was teaching me anout the UI 1 minute after seeing it for the first time so they are doing something right.

Offline

 

#13 2007-06-10 01:49:50

sjhalasz
Scratcher
Registered: 2007-05-26
Posts: 6

Re: REM Statements

It would probably be enough for my purposes if "Say ... for 0 Seconds" didn't flash on the screen.  There's not much real estate for a lot of comments and too much is as bad as none.  Changing the parameter to a variable that may be >0 seconds then gives you a nice trace of comments you can turn on and off.

Offline

 

#14 2007-06-10 11:37:07

DrJim
Scratcher
Registered: 2007-05-26
Posts: 100+

Re: REM Statements

On the subject of remarks/comments - I actually miss the ability to "comment out" a line of code more than I do the comment feature itself. Several work-arounds for the latter have been suggested, but so far I haven't figured out a way to do the former.

I would also like to see this implemented a "disable line" command separate from the comment/remark implementation.  This approach is used in Alice and seems to work pretty well - it also keeps two really separate tasks (giving information vs. disabling code) quite clearly separated.

Offline

 

#15 2007-06-10 16:06:28

kevin_karplus
Scratcher
Registered: 2007-04-27
Posts: 1000+

Re: REM Statements

You can use "repeat 0" to comment out code or disable it.  Putting it around part of a block of code does require some awkward disassembly and assembly of the script.

Offline

 

#16 2007-06-14 19:42:22

mungojelly
Scratcher
Registered: 2007-05-19
Posts: 35

Re: REM Statements

Changing anything in Scratch requires awkward disassembly and assembly.  It should be easier to grab a block out of the middle or shove one in.

How about this, instead of "If 1 = 2" how about: "If Debug = 1"?  That feels kind of harmonious, somehow!  I'm not sure how well it would work for debugging in practice!?  (Though it would work well if there was a step mode in Scratch, which there ought to be...)

Now I'm imagining how we could teach the kids unit testing!  Make all of the comments test-fail messages that should never be hit.  Point towards spriteX, turn 180 degrees, go 20 steps, if distance to spriteX < 15, say "We've just tried to go away from spriteX, so now we shouldn't be close to it!"

It's all in good fun, but really a comment block just makes sense, really.

<3

Offline

 

#17 2007-06-14 22:23:24

DrJim
Scratcher
Registered: 2007-05-26
Posts: 100+

Re: REM Statements

A couple of tricks to "comment out code" and disable a broadcast without having to move too much stuff around:

At the sending side - change the message to a dummy (i.e., "nothing")

At the receive side - just move the rest of the code away from the "when I receive <xxx>" block.  (Note: This still sends an ack so "broadcast <xxx> and wait" commands don't get hung up.)

Offline

 

Board footer