Loading...

Even though they're handy, comments aren't the answer for everything.

Comments can make it easier to understand the code you've built, but sometimes designers overuse comments. Overuse of comments causes code to look more cluttered, which defeats the purpose of adding comments in the first place.

team, working together on a coding project

For example: If someone else is reviewing your code, each time they run into a comment, they'll stop to read it. They assume it is important information. If you overuse comments or include unimportant information in them, your reviewer will become impatient. To save time, they may skip or simply not read some comments, which could lead to them missing some needed information.

Additionally, excessive commenting can slow the time it takes for a page to display in a browser. Even though comments aren't displayed after the code is parsed, the browser does have to read through each comment to determine its function. If you wrote a comment for every line of code, you'd double the size of your file, and the time it takes for the page to load would increase.

We've been following certain practices with code writing—like each tag going on a new line and indenting for nested items—because it makes the code more readable. The more readable your code is, the less need there is to explain it in a comment. It’s safe to assume that anyone viewing your source file is fluent in the code. With that in mind, limiting your comments to truly helpful information is considered best practice.

To differentiate between ideal and trivial uses of comments, work through the activity below. Look at each code excerpt and decide if the use of comments is helpful or unnecessary.

Which one?

<table><!-- Start of Table -->
  <tbody><!-- Start of Table Body -->
    <tr><!-- Start of Table Row -->
      <td>...</td>
      <td>...</td>
    </tr><!-- End of Table Row -->
  </tbody><!-- End of Table Body -->
</table><!-- End of Table -->
Helpful
Unnecessary
<!--Company History-->
<h3>About Us</h3>
<p>Our company has had strong roots in 
the community since 1935...</p>
Helpful
Unnecessary
<ol>
  <li>Preheat oven...</li>
  <li>Mix ingredients...</li>
  <li>Bake..</li>
  <li>Let cool..</li>
</ol><!--End of Ordered List-->
Helpful
Unnecessary
<ul>
  <li>Dogs
    <ul>
      <li>Breed</li>
      <li>Behavior</li>
      <li>Diet</li>
      <li>Personality</li>
    </ul><!--End Dogs List-->
  </li><!--End Dogs Category-->
  <li>Cats
    <ul>
      <li>Breed</li>
      <li>Behavior</li>
      <li>Diet</li>
      <li>Personality</li>
    </ul><!--End Cat List-->
  </li><!--End Cat Category-->
  <li>Birds
    <ul>
      <li>Breed</li>
      <li>Behavior</li>
      <li>Diet</li>
      <li>Personality</li>
    </ul><!--End Bird List-->
  </li><!--End Bird Category-->
</ul>
Helpful
Unnecessary
<p>Fill out the following form to complete your registration process.</p>
<!--<form>
    ...
    <button type="submit">Submit Form</button>
</form>-->
Helpful
Unnecessary
<!--Research Paper-->
<!--Introduction Paragraph-->
<p>...</p>
<!--Findings Paragraph-->
<p>...</p>
<!--Conclusion Paragraph-->
<p>...</p>
<!--Summary Paragraph-->
<p>...</p>           
<!--END Research Paper-->
Helpful
Unnecessary

You got # out of # correct. Click the Retry button for another attempt.

You got a perfect score. Great job!