Binary Operator in Name — Code Smells Catalog Skip to content

Binary Operator in Name

Couplers Names Code SmellLinguistic Smell Within Class

If a method has "and" or "or" in its name, it's confessing to doing two things, and that confession is an invitation to split it in half.

2 min read 1 source

Overview

This is straightforward: method or function names that have binary bitwise operators like AND and OR are obvious candidates for undisguised violators of the Single Responsibility Principle right out there in the open. If the method name has and in its name and then it does two different things, then one might ask why it is not split in half to do these two other things separately? Moreover, if the method name has or then it not only does two different things but also, most likely, it has a stinky Flag Argument which is yet another Code Smell.

This code smell might happen not only in the method names, even though it is the place to look for in the vast majority of this kind of smell, but also in the variables.

Problems

Single Responsibility Principle Violation

Names with conjunction words strongly suggest that something is not responsible for just one thing.

Refactoring

  • Extract Method

Sources

Browse All 56 Smells