Rescue Dawn: Anti-Patterns: How to Save your Code?
Anti-Patterns Credit: dipbd1

Rescue Dawn: Anti-Patterns: How to Save your Code?


Anti-Patterns

Patterns in codebase that solve problem but consequently causes more problems. It is the opposite of design pattern. In software engineering, anti-patterns are common and unavoidable. It can quickly grow big and go out-of-control.

Types

Several types of anti-pattern exists. Some are development and others are management related. Here we discuss some notable software development related anti-patterns.


The Blob aka God Class: The name derives from a classic science-fiction movie "The Blob", released in 1958. A class is called Blob or God if it has multiple responsibilities, concerns and behaviors, thus it violates separation of concern principle. If we continue to write all the concerns in a single class, it will grow very big, unmanageable and error prone.

Example: Writing database connection, configuration, validation, API in the same class.

Solution: Always follow Single Responsibility principle.


Spaghetti Code: A code so unstructured and unplanned that the flow of program is very hard to determine and control.

Example: Implementing a solution poorly in a object-oriented paradigm violating multiple principle (e.g. DRY, KISS)

Solution: Always plan before start writing the code and come up with a solution verified by an experienced programmer.


Golden Hammer: This is a cognitive bias. Implementing a well designed, sound structed and already tested code repeatedly causes this problem. Here, the programmer thinks , one solution or tool can solve every problem and he/she implements it in a new project every time.

Example: The login functionality of Facebook and Google is same, so implementing the authentication code of Facebook in Google.

Solution: When faced the same problem, think at first from the ground-up. First check if the requirements and constraints are same or not.


Lava Flow aka Dead Code: An unknown code fragment that no one can identify and remember. This code unnecessarily consumes recourses and processing power. Moreover, programmers are afraid of deleting it because

Example: Loading some records from database during user login whose utility is not clear during authentication process.

Solution: The cure is painful, refactoring is the only way.


Boat Anchor: A piece of code left in the codebase which has no current use. This types of code confuses programmer. Furthermore, these codes complicates the system, may slows down system or build time.

Example: A validation code block which demands requires costly third-party API calls which has no use in current context.

Solution: Applying best practices from the project kickstart.


Cut/Paste: Cutting known piece of solution code blocks to a different project can have unexpected outcomes and problems.

Example: Cutting database connection code from one part to another part of software.

Solution: Some degree of copy/paste is inevitable in the same software or similar software. But this process needs a formal approach.


Poltergeists: A piece of code that can be easily moved or merged into another class. They are short lived and no need separation.

Example: An algorithm implementation for a specific task.

Solution: Using proper design patterns (e.g. factory) can easily mitigate this problem.

That's all folks!

Dip Chowdhury

Software Engineer, Trying to connect the dots.

1y

I don't like to do it, but as we know we have very little control over the past and future, so what best we can do is, make something that works in the present. But then again the question comes, what will happen in the future?

To view or add a comment, sign in

More articles by Sadat Rafsanjani

  • Query Optimization: Basics

    So, without further due, lets get started. What is it? A set of techniques to improve database performance and reduce…

    2 Comments
  • Database Indexing

    So, without further due, lets get started. What is it? Indexing is a technique that is used to minimize database…

  • Software Firm? Product-based or Service-based

    So, without further due, lets get started. What it is? A software firm creates or innovates new ideas, products and…

    2 Comments
  • Bloom Filter

    What is it? A space efficient probabilistic (uses probability math) data structure. It is used to search element in a…

  • Linux File Permissions

    So without further due lets get started. What is it? File permission is a part of Linux administration where the system…

  • Tech Layoffs: You are Not Safe

    Tech layoffs are common these days. In fact experts are saying the chance of worsening is more likely to happen this…

  • Tech Talk 04: Integrating Google Translate in Angular

    So, without further due, lets get started. Introduction Google translate library is available to use for free.

  • Tech Talk 03: JavaScript Map vs. Filter vs. Reduce

    So without further due, lets get started. Map A map is an array function that operates on an array.

  • Tech Talk 02: Two-Phase Commit (2PC)

    So, without further due, lets get started! What is 2PC? Two-Phase Commit aka Tupac (2PC) is a protocol or distributed…

  • Tech Talk 01: JavaScript Event Loop

    For those of us working in JavaScript for a while, we all know about the event loop mechanism. In this talk, we discuss…

Insights from the community

Explore topics