Do not perform more than requested.
TL;DR: Unless you need atomicity, do not perform more than one task.
Problems
- Coupling
- Single Responsibility Principle violation
- Readability
- Low Cohesion
- Testability
Solutions
- Break the function
Sample Code
Wrong
def fetch_and_display_personnel():
data = # ...
for person in data:
print(person)
Right
def fetch_personnel():
return # ...
def display_personnel(data):
for person in data:
print(person)
Detection
Functions including "and" are candidates. However, we need to check them carefully since there might be false positives.
Tags
- Readability
- Naming
Conclusion
We should avoid doing more than needed, and our functions should be both minimal and atomic.
More Info
Credits
This smell was inspired by
If it takes more than a sentence to explain what you are doing, it’s almost always a sign that what you are doing is too complicated.
Sam Altman
Software Engineering Great Quotes
Maxi Contieri ・ Dec 28 '20
This article is part of the CodeSmell Series.
Top comments (0)