• Tester-AI
    • Artificial Intelligence(A.I)
      • Applications of Artificial Intelligence in Medicine
      • Artificial Intelligence Applications in Industry
      • Artificial Intelligence in Agriculture
      • Application of AI in the field of traffic
      • Application of AI in the domestic sphere
      • Artificial Intelligence in Education
    • Programmers Worldwide
  • 12. Developers mistakes
    • 1. Underestimating the importance of code quality
    • 2. Use of inappropriate data structures
    • 3. Deteriorate the code
    • 4. Commenting on obvious things
    • 5. To think if something works, it's done right
    • 6. Obsession with performance
    • 7. Not picking the right tools
    • 8. Misunderstanding the Relationship between Code and Data
    • 9. The Invention of the Wheel
    • 10. Incorrect attitude towards code inspection (code review)
    • 11. Wrong attitude towards mistakes
    • 12. Do not rest.
  • Benefits of the Tester-AI
  • Economic justification
  • Tokenomics
  • Roadmap
  • Conclusion
Powered by GitBook
On this page
  1. 12. Developers mistakes

4. Commenting on obvious things

Most comments can be replaced with names of variables and functions. Before you write a comment, remember this.

For example, code like this:

// This function sums only odd numbers in an array
const sum = (val) => {
  return val.reduce((a, b) => {
    if (b % 2 === 1) { // If the current number is odd
      a+=b;            // Add current number to accumulator
    }
    return a;          // The accumulator
  }, 0);
};

You can replace it with this:

const sumOddValues = (array) => {
  return array.reduce((accumulator, currentNumber) => {
    if (isOdd(currentNumber)) { 
      return accumulator + currentNumber;
    }
    return accumulator;
  }, 0);
};

But sometimes you can only clarify the code with a comment. In that case, focus on the question: "WHY this code is needed," not "WHAT this code does. Here's an example of code where comments only clutter up the code:

// create a variable and initialize it to 0
let sum = 0;
// Loop over array
array.forEach(
  // For each number in the array
  (number) => {
    // Add the current number to the sum variable
    sum += number;
  }
);

Don't do that if you are a programmer. And if you are the employer of such programmers, fire them right now.

Previous3. Deteriorate the codeNext5. To think if something works, it's done right

Last updated 2 years ago