DEV Community

Discussion on: Code Comments Are Stupid

Collapse
 
slourenco profile image
SLourenco

Apart from the reasons you gave, I would argue that unit tests also remove the need for comments in several situations.

Aside from all the benefits that unit tests bring, they also can clearly define the intent of each code block. In your regex example, I would say that even without refactoring the method to simpler regex expressions, you can have multiple tests that help understand what that method is validating.

And unlike comments, unit tests can be enforced to be valid and updated when the code changes.

Collapse
 
matjones profile image
Mat Jones

That’s a very good point. The only caveat is that you have to actually open the separate file for the unit tests, which isn’t a big deal it’s just another level of separation between the code and it’s specifications.

Collapse
 
rossdrew profile image
Ross

You don't always need to. Many IDEs will run them in a window and display test names and failures. That can be explanatory enough in many cases