Knowee
Questions
Features
Study Tools

In your own words, explain what code should and shouldn't be commented.

Question

In your own words, explain what code should and shouldn't be commented.

🧐 Not the exact question you are looking for?Go ask a question

Solution

Code commenting is a crucial part of programming. It helps to explain the functionality of the code and makes it easier for others (or even yourself in the future) to understand what the code is doing.

What should be commented:

  1. Complex code: If a piece of code is complex and not straightforward to understand, it should be commented. This helps to explain the logic behind the code.
  2. Important decisions: If a particular decision was made while writing the code (like using a specific algorithm or data structure), it should be commented. This helps to understand the reasoning behind the decision.
  3. Code that might be changed in the future: If a piece of code is likely to be updated or modified in the future, it should be commented. This helps to understand what the code is doing and makes it easier to make changes.

What shouldn't be commented:

  1. Obvious code: If a piece of code is self-explanatory, it doesn't need to be commented. For example, a line of code that is simply assigning a value to a variable doesn't need a comment.
  2. Over-commenting: Too many comments can make the code cluttered and harder to read. It's important to strike a balance between commenting and keeping the code clean.
  3. Outdated comments: If a piece of code has been changed or updated, the corresponding comment should also be updated. Outdated comments can cause confusion and should be avoided.

This problem has been solved

Similar Questions

As programs get bigger and more complicated, they get more difficult to read. This is one reason why programmers should use comments in their code.

Comments are written for __________.a.)anyone who reads the programb.)the end userc.)the interpreterd.)only the programmer

What do you put at the end of each line of code that does not create a method or a class?

Briefly describe what you learned when you created this code sample:

How can comments be implemented in PHP?Question 11Select one:a.// commented code to the end of the lineb./* commented code can be on multiple lines */c.# commented code to the end of the lined.All of the above

1/1

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.