1 / 8

Using Comments

Learn how to use comments in your code to document and explain your code, making it easier for others to understand and collaborate on your projects.

roscoej
Download Presentation

Using Comments

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Using Comments http://www.alice.org/resources/lessons/using-comments/

  2. Using Comments What is a Comment? A comment is text is used to document code. It is for other programmers to read but is ignored by a compiler or interpreter. Generally you can find comments stylized using variations of the following: /* the comment lives hereand can be multiple lines*/ or what Alice uses // for individual lines you use this format// however, you can put multiple of these in a row

  3. Using Comments Why Comment To layout and outline your program before coding to help guide your development. To help others understand what your program does when reviewing or collaborating on a project. To help you navigate and debug your code base

  4. Using Comments Documenting Your Program A Header comment is put at the beginning of your program file and can include: Authors - who wrote it Date - when it was written or last modified Description - a summary of what the program does

  5. Using Comments In Line Commenting Comments can be added in line with your program code to summarize a specific task or problem the code addresses This can be helpful to: • Quickly navigate to components for debugging • help other programmers understand what the code is intended to do

  6. Using Comments Describe Custom Methods When creating custom methods and functions it is a good idea to add comments to them. Good information to include are: Preconditions: What assumptions are being made for the method to behave correctly (i.e. A hop method may assume that the object is standing upright) Action: A summary of what the procedure does Postconditions: What can be assumed about the state of the object after the method has executed. (i.e. after a hop, the object is standing upright)

  7. Using Comments Adding Comments Drag it in from the control structures menu. Edit the text by clicking into the tile. Drag to trash or right click to delete.

  8. Using Comments Converting Code to Comments Using commenting syntax is a way to disable code so that the code statements are ignored by compilers. This is commonly used to disable code for testing or debugging purposes. Right click on code statements and select disable or enable to toggle the state This is then displayed with backslashes and grayed out to show that it has been commented out. Be sure that the conditions resulting from the code are not needed for later code to perform as expected

More Related