Commenting Code in Scratch

Commenting in Scratch

Comments in Scratch are a handy tool that is easy to use once you understand the function and purpose. Commenting is one of the core best practices in any programming language and environment, and building this skill into your early Scratch projects will build a solid foundation for future development. Additionally, commenting your code in Scratch will help establish an effective communication system between learners. For example, much of the example projects that are created for DHF youth have been extensively commented so that they’re better able to understand the example projects. Commenting may seem like an unnecessary extra step at first, but with practice it will become second nature.

How to Use Comments

Take a look at this example Scratch project. A friendly robot named CommentBot is demonstrating several types of comments in Scratch. If you want to open it in a new window, go ahead and click on the image.

IntGames - Commenting Scratch Example Project

While comments can be used in any way that you see fit, here are two common purposes:

  1. General Comments: These are comments that aren’t attached to any particular code. Instead these comments can provide an overview of the project. Here’s a closer look at this comment type from the above example:IntGames - Commenting in Scratch - General Comment
  2. Another comment type that is displayed in the above example is called a Mini-comment. In the zoomed in example above, this type of comment is attached to the “when Start clicked.” To make a comment a mini-comment, just click the gray arrow to toggle between mini and full.
  3. Specific Comments: These are comments that are attached to a particular code block or script. Specific comments can be used to present a walkthrough of the script, provide clarity and insight into the purpose or function of the scripts, and ask questions for viewers. These are just some examples of how comments can be used. Here’s a closer look at this comment type:
    IntGames - Commenting in Scratch - Specific Comment
  4. Notice that there is a mini-comment labeled “Motion mechanic” at the very top of the code block, with the longer comment attached to a chunk of the script. This is a common way of commenting in Scratch, where you can use mini-comments to denote sections or certain mechanics.

Activity: Adding Comments to the Project

The purpose of this activity is to practice adding the different types of comments to your project. Practice using each comment type so that you can build an idea of how and when to use each type.

Steps:

  1. Select the sprite or backdrop where you want to add comments. This will focus the code editor to the scripts attached to that particular asset.
  2. Right-click on the code you want to comment and select “add comment” from the menu. This will create the comment box.
  3. Notice that the comment defaults as a full comment that is attached to the block that you right-clicked. To add text, just type in the comment’s text field. If you want to move the comment, just drag it to the new destination.
  4. Add the following comments:
    • Mini-comment: Add this to the first block in your motion script describing that it is the motion mechanic.
    • Specific Comment: Provide some comments that are attached to your motion script. What you add is up to you. If you’re stuck, look at the above example for some ideas.
    • General Comment: Add a general comment to either your sprite or backdrop. If you’re looking for some ideas, check the above example for some inspiration.
  5. To resize and adjust your comments, just left click and hold the bottom right corner of the comment box.
  6. Keep practicing this. The more that you practice and understand how to integrate commenting into your workflow, the more natural it will become.

Related Posts

  • the Scratch logo with the Scratch cat mascot

    What is Commenting? Annotations by the programmer with the intent of making the code easier…

  • the Scratch logo with the Scratch cat mascot

    Managing Code One important soft-skill that is worth mentioning is understanding the importance of managing…

  • rainbow squiggly scratch art made with a CD

    This is a fun and creative project and something great to do with old CDs…