Problems

  • Maintainability
  • Obsolete Documentation

Solutions

  1. Refactor methods.

  2. Rename methods to more declarative ones.

  3. Break methods.

  4. If a comment describe what a method does, name the method with this description.

  5. Just comment important designs decisions.

Examples:

  • Libraries
  • Class Comments
  • Method Comments

Sample Code:

Wrong

<?

	  final class ChatBotConnectionHelper(){
	    //ChatBotConnectionHelper is used to create connection strings to Bot Platform
	    //Use this class with getString() function to get connection string to platform

	    public $id; //ChatBot Id

	    function getId(){ //Gets id value
	    function setId($id) { //Sets id value

	    function getString(){
	      //Get Connection String from Chatbot

	      //....

	  }

Right

<?

	  final class ChatBotConnectionSequenceGenerator(){

	    private $name; 

	    function connectionSequence(){

	      ....

	  }

Detection

Linters can detect comments and check the ratio comments / lines of code against a predefined threshold.

#clean-code #code-smells #programming #software-development

Code Smell 05 — Comment Abusers
1.10 GEEK