Skip to content

Latest commit

Β 

History

History
88 lines (51 loc) Β· 2.07 KB

File metadata and controls

88 lines (51 loc) Β· 2.07 KB

Code Smell 85 - And Functions

Code Smell 85 - And Functions

Don't perform more than requested.

TL;DR: Unless you need atomicity, don't perform more than one task.

Problems πŸ˜”

  • Coupling
  • Single Responsibility Principle violation
  • Readability
  • Low Cohesion
  • Testability

Solutions πŸ˜ƒ

  1. 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 🏷️

  • Bloaters

Level πŸ”‹

[x] Beginner

Conclusion 🏁

We should avoid doing more than needed, and our functions should be both minimal and atomic.

More Information πŸ“•

What exactly is a name - Part II Rehab

Credits πŸ™

Photo by Paul on Unsplash

This smell was inspired by

Twitter


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


This article is part of the CodeSmell Series.

How to Find the Stinky Parts of Your Code