Code Smell 229 - Red Tape

Code Smell 229 - Red Tape

You overcomplicate your code

TL;DR: Avoid Accidental complexity and bureaucracy

Problems

  • Accidental Complexity
  • Readability
  • Bijection Fault

Solutions

  1. Asign the responsibilities to real-world objects using the MAPPER

Context

A "red tape" code smell could relate to unnecessary complexity, bureaucracy, or excessive configuration that makes the codebase harder to understand or maintain.

Sample Code

Wrong

class VotingSystem:
    def __init__(self, config):
        self.config = config

    def validate_voter(self, voter_id):
        if self.config['voter_verification_enabled']:
            # Code to verify the voter's identity goes here

    def cast_vote(self, voter_id, candidate):
        if self.config['voting_enabled']:
            # Code to record the vote goes here

    def generate_vote_report(self):
        if self.config['generate_report']:
            # Code to generate a voting report goes here

    def audit_voting_system(self):
        if self.config['audit_enabled']:
            # Code to perform an audit of the voting system goes here

    # ... other voting-related methods ...

# Usage
config = {
    'voter_verification_enabled': True,
    'voting_enabled': False,
    'generate_report': False,
    'audit_enabled': True
}

voting_system = VotingSystem(config)

# Voter validation, voting, report generation, and auditing are handled based on the configuration.        

Right

class VoterVerification:
    def verify_voter(self, voter_id):
        # Code to verify the voter's identity goes here

class VotingMachine:
    def cast_vote(self, voter_id, candidate):
        # Code to record the vote goes here

class VoteReporter:
    def generate_report(self):
        # Code to generate a voting report goes here

class VotingAuditor:
    def audit_voting_system(self):
        # Code to perform an audit of the voting system goes here

# Usage
voter_verification = VoterVerification()
voting_machine = VotingMachine()
vote_reporter = VoteReporter()
voting_auditor = VotingAuditor()

# Voter verification, vote casting, report generation, and auditing are handled separately.        

Detection

[X] Semi-Automatic

Some tools can guess you are bloating your objects with unnecessary responsibilities.

Tags

  • Bloaters

Conclusion

The red tape code smell is evident as developers need to navigate the complex configuration to determine which features are active.

This not only adds unnecessary complexity but also increases the likelihood of misconfigurations that could impact the integrity of your system.

Relations

Disclaimer

Code Smells are my opinion.

Credits

Photo by the blowup on Unsplash


A Fallacy of Software: If it works, and we don't change anything, it will keep working.

Jessica Kerr


This article is part of the CodeSmell Series.


要查看或添加评论,请登录

Maximiliano Contieri的更多文章

  • Code Smell 295 - String Concatenation

    Code Smell 295 - String Concatenation

    Untangling the string mess in your code TL;DR: Avoid string concatenation for complex strings, use templates. Problems…

  • Code Smell 294 - Implicit Return

    Code Smell 294 - Implicit Return

    Your language adds clever features. Making YOU more obsolete TL;DR: Overusing implicit returns makes your code harder…

  • The Great Programmer Purge: How AI Is Taking Over the Tech Workforce

    The Great Programmer Purge: How AI Is Taking Over the Tech Workforce

    How AI is Redefining the Role of Programmers in the Tech Industry TL;DR: AI-generated code outperforms lazy…

    1 条评论
  • Refactoring 024 - Replace Global Variables with Dependency Injection

    Refactoring 024 - Replace Global Variables with Dependency Injection

    Break Hidden Dependencies for Cleaner Code TL;DR: Replace global variables with dependency injection to improve…

  • 10 More Simple Tips to Boost Your Productivity x2

    10 More Simple Tips to Boost Your Productivity x2

    The previous article on life hacks was a huge success. Let's start the year with more productivity tips! TL;DR: More…

  • Code Smell 293 - isTesting

    Code Smell 293 - isTesting

    Don’t let test code sneak into production TL;DR: Avoid adding isTesting or similar flags. Problems ?? Leaky abstraction…

  • Refactoring 001 - Remove Setters

    Refactoring 001 - Remove Setters

    Setters violate immutability and add accidental coupling TL;DR: Make your attributes private to favor mutability…

  • Code Smell 292 - Missing Return

    Code Smell 292 - Missing Return

    When your code loses its way TL;DR: Missing return statements cause unexpected behavior. Problems ?? Silent failures…

  • Code Smell 291 - Mutable Keys

    Code Smell 291 - Mutable Keys

    Changing Keys, Losing Values TL;DR: When you use mutable objects as keys in hashed collections, changing them breaks…

    2 条评论
  • Refactoring 023 - Replace Inheritance with Delegation

    Refactoring 023 - Replace Inheritance with Delegation

    Transform your rigid inheritance into flexible delegations TL;DR: Replace restrictive inheritance hierarchies with…

社区洞察

其他会员也浏览了