# Refactoring 005 - Replace Comment with Function Name

> TL;DR: Don't comment on what you are doing. Name what you are doing. 

# Problems Addressed

- Bad Names

- Comments

# Related Code Smells

%[https://maximilianocontieri.com/code-smell-05-comment-abusers]

%[https://maximilianocontieri.com/code-smell-75-comments-inside-a-method]

%[https://maximilianocontieri.com/code-smell-06-too-clever-programmer]

# Steps

1. Name the function with the previous comment

2. Remove the Comment

# Sample Code

## Before

[Gist Url]: # (https://gist.github.com/mcsee/ec23401dcd3a6e03ca6613d3c58867d0)
```php
<?

function repl($str) {
  // Replaces with spaces the braces 
 
  $str = str_replace(array("\{","\}")," ",$str);
  return $str;

}
```

## After

[Gist Url]: # (https://gist.github.com/mcsee/25b76368b744b08194ea3c853fc8f5e8)
```php
<?

// 1. Name the function with the previous comment
// 2. Remove the Comment

function replaceBracesWithSpaces($input) {
  
  return str_replace(array("\{","\}")," ", $input);

}
```

# Type

[X] SemiAutomatic

Some IDEs have this refactoring although naming is not fully automatic.

# Why the code is better?

Comments always lie.

It is hard to maintain comments.

On the contrary, Functions are alive and self-explanatory.

# Limitations

As always, very important design decisions are valid comments.

# Tags

- Comments

# See also

[What is in a name?](https://maximilianocontieri.com/what-exactly-is-a-name-part-i-the-quest)

# Credits

Photo by [Jannik Texler](https://pixabay.com/users/texler-3778340/) on [Pixabay](https://pixabay.com/)

* * * 

This article is part of the Refactoring Series.
