SlideShare a Scribd company logo
10 Code Anti-Patterns to Avoid in Software
Development
By: Ahmed Salama
Intro
The general performance, maintenance, and scalability of an application or system depend highly on the code
structure. Unfortunately, due to the complex nature of software development, developers working on an application
might resolve to use anti-patterns as a quick solution to a problem. Unfortunately, most of these anti-patterns end up
causing problems to the general functionality of an application and future code maintenance.
Here are 10 code anti-patterns you should avoid in software development:
1. The Golden Hammer
2. Spaghetti Code
3. Reinventing the Wheel
4. Dependency Hell
5. God Object or God Class
6. Hard Coding
7. Boat Anchor
8. Lava Flow
9. Copy – Paste Programming
10. Cargo – Cult Programming
Intro
● In other words, anti-patterns might look like a good solution at first but eventually turn out to
be the opposite, doing more harm than good.
● Anti-patterns have a negative impact on your software. They either introduce more bugs,
raise security issues, or hinder code readability and maintenance. Below are ten code
anti-patterns that will help you improve how you write your code.
1- The Golden Hammer
● This anti-pattern is a well-known solution in software development and is commonly used to
make the development process much faster. It refers to the concept of using the same
solution used to solve problem “A” to solve problem “B.”
● In software development, every problem has a unique solution. Always remember to
choose the right tools, libraries, frameworks, and architecture for every problem. It is always
recommended to come up with at least two solutions for each problem. Weigh the pros and
cons of each before deciding to implement one that you find suitable.
2- Spaghetti Code
● Have you ever looked at a plate of spaghetti and just observed how each spaghetti is
tangled and jumbled with each other? You can’t even know the start or the end of every
spaghetti. Well, in software development, it is not a surprise to come across code similar to
that.
● Most applications today are a victim of this. It mainly arises when a developer starts working
on a project before taking note of the program flow and understanding the documentation
well.
● Things become worse as your program grows. Your already messy code becomes messier.
You start having multiple functions in different files invoking each other. You start copying and
pasting a piece of already working code to solve a problem in a different part of your
application. Whenever you delete a single function, half of the application breaks.
3- Reinventing the Wheel
● A scenario where developers opt to come up with a custom solution instead of using the
existing solution in the market with the help of API and libraries.
● Think of a company that wants to add a blog/posts page on its website. It will take time and
resources if developers decide to develop a custom CMS (Content Management System)
from scratch. Instead, they can opt for already existing solutions such as WordPress, Joomla,
and even headless CMS like Strapi, Ghost, or Contentful.
4- Dependency Hell
● In most cases, when you focus much on avoiding “Reinventing the Wheel,” you will most
likely fall into the “dependency hell.” Instead of developers developing custom solutions, they
import many third-party libraries into their projects. Unfortunately, some of these libraries
also rely on other external libraries.
●
5- God Object or God Class
● This anti-pattern goes against the Principle of Single Responsibility in programming.
According to this principle, every class should only have a single responsibility or single
purpose in your project.
● This issue arises when developers ignore creating additional classes during the project’s
initial phase and plan to do that later. Unfortunately, they continue adding more
responsibilities to the initial class that even other functions and methods depend solely on.
In most cases, it is perceived as the application’s main class.
● Ex: guest_email_settings, guest_sms_settings
6- Hard Coding
● This anti-pattern is most common in web development. A developer directly adds various parameters
into the source code instead of fetching them from, say, a database, API, user input, the ‘.env’ file,
etc.
● Two main issues arise with this anti-pattern. The first is security. If you hardcode an authentication
parameter such as an API access token or JWT token, somebody can easily access it by just viewing
the source code from the browser.
● The other issue is environmental change. When you hardcode parameters when working in
“development,” your application will work perfectly. However, the application breaks when you push
the changes to the “production” environment. You will need to edit the source code every time to suit
every environment.
7- Boat Anchor
● This anti-pattern mainly arises when developers code an application with the “what if” question in
mind. What if I need to add this functionality in the future? What if this particular scenario occurs in
my code while in production? What if a user tries to access this feature?
● With all these “what if” questions in mind, developers eventually write additional lines of code not
needed by the application at that particular moment. According to them, these extra lines might
become helpful in the future. Unfortunately, this anti-pattern does more harm than good.
● This “unneeded” code becomes like a “boat anchor” It does nothing as of that moment, but your
application still has to carry it because you think you might require that code in the future.
8- Lava Flow
● Lava flow anti-pattern refers to the concept where developers have to deal with redundant or
low-quality code but appears to have a role in the general working of the application.
Removing or editing this code becomes quite risky since you are unaware of what will
happen to the app.
● Most of these issues arise from legacy code written during the project’s initial phase. Maybe
the developer did not follow the documentation, or the project was moving too fast, and they
didn’t have time to optimize and refactor the code.
● The best solution to lava flows is extensive testing and refactoring. Unfortunately, it’s easier
said than done. Developers will spend much time trying to understand the code, and they
might end up leaving it as it is for fear of breaking the application.
9- Copy – Paste Programming
● most copy and paste code snippets from stack overflow, GitHub, blogs, and youtube videos.
● Unfortunately, most developers don’t analyze the impact of this copy-pasted code; the only
thing that matters is that “it works!”
● You should test this copied code very well and make sure it covers all your test cases!
10- Cargo – Cult Programming
● This anti-pattern derives its name from an interesting story. After the second world war,
tribal societies from the south pacific came into contact with the advanced Western
Civilization. It was the first time for the natives to see manufactured products such as radios,
Coca-Cola, etc., brought to the island.
● Since they had never seen such things (cargo) before and didn’t understand how they were
manufactured, they saw the Americans as gods. They started imitating whatever the
Westerners were doing, hoping the gods would send more cargo to the island. That led to the
rise of the name “cargo cults.”

More Related Content

Similar to 10 Code Anti-Patterns to Avoid in Software Development.pdf

Technologies for startup
Technologies for startupTechnologies for startup
Technologies for startup
Dzung Nguyen
 
Droidcon thessaloniki 2015
Droidcon thessaloniki 2015Droidcon thessaloniki 2015
Droidcon thessaloniki 2015
Raymond Chenon
 
Software Development Standard Operating Procedure
Software Development Standard Operating Procedure Software Development Standard Operating Procedure
Software Development Standard Operating Procedure
rupeshchanchal
 
Introduction to Go
Introduction to GoIntroduction to Go
Introduction to Go
Simon Hewitt
 
GDG Morgantown, WV: Write code you can depend on!
GDG Morgantown, WV: Write code you can depend on!GDG Morgantown, WV: Write code you can depend on!
GDG Morgantown, WV: Write code you can depend on!
Logan Spears
 
Advantages and Disadvantages of React Native App Development
Advantages and Disadvantages of React Native App DevelopmentAdvantages and Disadvantages of React Native App Development
Advantages and Disadvantages of React Native App Development
APPNWEB Technologies
 
Challenges of React Native App Development_ Effective Mitigation Strategies.pdf
Challenges of React Native App Development_ Effective Mitigation Strategies.pdfChallenges of React Native App Development_ Effective Mitigation Strategies.pdf
Challenges of React Native App Development_ Effective Mitigation Strategies.pdf
Andolasoft Inc
 
Go_ Building Web Applications ( PDFDrive.com ).pdf
Go_ Building Web Applications ( PDFDrive.com ).pdfGo_ Building Web Applications ( PDFDrive.com ).pdf
Go_ Building Web Applications ( PDFDrive.com ).pdf
RicardoSousa631355
 
Why big organizations like tesla, facebook, walmart, skype are using react na...
Why big organizations like tesla, facebook, walmart, skype are using react na...Why big organizations like tesla, facebook, walmart, skype are using react na...
Why big organizations like tesla, facebook, walmart, skype are using react na...
MoonTechnolabsPvtLtd
 
Continuous integration
Continuous integrationContinuous integration
Continuous integration
Boris Dominic
 
Basics of-software-development
Basics of-software-developmentBasics of-software-development
Basics of-software-developmentlukaramishvili
 
How To Become A Good C# Programmer
How To Become A Good C# ProgrammerHow To Become A Good C# Programmer
How To Become A Good C# Programmer
LearnItFirst.com
 
How to use electron to build multi platform desktop applications
How to use electron to build multi platform desktop applications How to use electron to build multi platform desktop applications
How to use electron to build multi platform desktop applications
Moon Technolabs Pvt. Ltd.
 
Quality Software Development
Quality Software DevelopmentQuality Software Development
Quality Software Development
Srinivasan Hariharan
 
Five Common Angular Mistakes
Five Common Angular MistakesFive Common Angular Mistakes
Five Common Angular Mistakes
Backand Cohen
 
Managing Software Dependencies and the Supply Chain_ MIT EM.S20.pdf
Managing Software Dependencies and the Supply Chain_ MIT EM.S20.pdfManaging Software Dependencies and the Supply Chain_ MIT EM.S20.pdf
Managing Software Dependencies and the Supply Chain_ MIT EM.S20.pdf
Andrew Lamb
 
Cinci ug-january2011-anti-patterns
Cinci ug-january2011-anti-patternsCinci ug-january2011-anti-patterns
Cinci ug-january2011-anti-patterns
Steven Smith
 
Open Source Project Management
Open Source Project ManagementOpen Source Project Management
Open Source Project Management
Semen Arslan
 
These are the top 7 alternatives to react native
These are the top 7 alternatives to react nativeThese are the top 7 alternatives to react native
These are the top 7 alternatives to react native
Moon Technolabs Pvt. Ltd.
 

Similar to 10 Code Anti-Patterns to Avoid in Software Development.pdf (20)

Technologies for startup
Technologies for startupTechnologies for startup
Technologies for startup
 
Droidcon thessaloniki 2015
Droidcon thessaloniki 2015Droidcon thessaloniki 2015
Droidcon thessaloniki 2015
 
Software Development Standard Operating Procedure
Software Development Standard Operating Procedure Software Development Standard Operating Procedure
Software Development Standard Operating Procedure
 
Introduction to Go
Introduction to GoIntroduction to Go
Introduction to Go
 
GDG Morgantown, WV: Write code you can depend on!
GDG Morgantown, WV: Write code you can depend on!GDG Morgantown, WV: Write code you can depend on!
GDG Morgantown, WV: Write code you can depend on!
 
Advantages and Disadvantages of React Native App Development
Advantages and Disadvantages of React Native App DevelopmentAdvantages and Disadvantages of React Native App Development
Advantages and Disadvantages of React Native App Development
 
Challenges of React Native App Development_ Effective Mitigation Strategies.pdf
Challenges of React Native App Development_ Effective Mitigation Strategies.pdfChallenges of React Native App Development_ Effective Mitigation Strategies.pdf
Challenges of React Native App Development_ Effective Mitigation Strategies.pdf
 
Go_ Building Web Applications ( PDFDrive.com ).pdf
Go_ Building Web Applications ( PDFDrive.com ).pdfGo_ Building Web Applications ( PDFDrive.com ).pdf
Go_ Building Web Applications ( PDFDrive.com ).pdf
 
Website qa
Website qaWebsite qa
Website qa
 
Why big organizations like tesla, facebook, walmart, skype are using react na...
Why big organizations like tesla, facebook, walmart, skype are using react na...Why big organizations like tesla, facebook, walmart, skype are using react na...
Why big organizations like tesla, facebook, walmart, skype are using react na...
 
Continuous integration
Continuous integrationContinuous integration
Continuous integration
 
Basics of-software-development
Basics of-software-developmentBasics of-software-development
Basics of-software-development
 
How To Become A Good C# Programmer
How To Become A Good C# ProgrammerHow To Become A Good C# Programmer
How To Become A Good C# Programmer
 
How to use electron to build multi platform desktop applications
How to use electron to build multi platform desktop applications How to use electron to build multi platform desktop applications
How to use electron to build multi platform desktop applications
 
Quality Software Development
Quality Software DevelopmentQuality Software Development
Quality Software Development
 
Five Common Angular Mistakes
Five Common Angular MistakesFive Common Angular Mistakes
Five Common Angular Mistakes
 
Managing Software Dependencies and the Supply Chain_ MIT EM.S20.pdf
Managing Software Dependencies and the Supply Chain_ MIT EM.S20.pdfManaging Software Dependencies and the Supply Chain_ MIT EM.S20.pdf
Managing Software Dependencies and the Supply Chain_ MIT EM.S20.pdf
 
Cinci ug-january2011-anti-patterns
Cinci ug-january2011-anti-patternsCinci ug-january2011-anti-patterns
Cinci ug-january2011-anti-patterns
 
Open Source Project Management
Open Source Project ManagementOpen Source Project Management
Open Source Project Management
 
These are the top 7 alternatives to react native
These are the top 7 alternatives to react nativeThese are the top 7 alternatives to react native
These are the top 7 alternatives to react native
 

More from Ahmed Salama

Seven Ways To Be a Healthy Programmer!.pdf
Seven Ways To Be a Healthy Programmer!.pdfSeven Ways To Be a Healthy Programmer!.pdf
Seven Ways To Be a Healthy Programmer!.pdf
Ahmed Salama
 
Introduction to web development
Introduction to web developmentIntroduction to web development
Introduction to web development
Ahmed Salama
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to Django
Ahmed Salama
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
Ahmed Salama
 
Quick Start to marketing.
Quick Start to marketing.Quick Start to marketing.
Quick Start to marketing.
Ahmed Salama
 
Distributed database
Distributed databaseDistributed database
Distributed database
Ahmed Salama
 
Konard zuse
Konard zuseKonard zuse
Konard zuse
Ahmed Salama
 
DDOS Attack
DDOS Attack DDOS Attack
DDOS Attack
Ahmed Salama
 
Introduction to Computer Science Department
Introduction to Computer Science DepartmentIntroduction to Computer Science Department
Introduction to Computer Science Department
Ahmed Salama
 

More from Ahmed Salama (9)

Seven Ways To Be a Healthy Programmer!.pdf
Seven Ways To Be a Healthy Programmer!.pdfSeven Ways To Be a Healthy Programmer!.pdf
Seven Ways To Be a Healthy Programmer!.pdf
 
Introduction to web development
Introduction to web developmentIntroduction to web development
Introduction to web development
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to Django
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
Quick Start to marketing.
Quick Start to marketing.Quick Start to marketing.
Quick Start to marketing.
 
Distributed database
Distributed databaseDistributed database
Distributed database
 
Konard zuse
Konard zuseKonard zuse
Konard zuse
 
DDOS Attack
DDOS Attack DDOS Attack
DDOS Attack
 
Introduction to Computer Science Department
Introduction to Computer Science DepartmentIntroduction to Computer Science Department
Introduction to Computer Science Department
 

Recently uploaded

Transform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR SolutionsTransform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR Solutions
TheSMSPoint
 
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket ManagementUtilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate
 
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata
 
Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
Ayan Halder
 
Empowering Growth with Best Software Development Company in Noida - Deuglo
Empowering Growth with Best Software  Development Company in Noida - DeugloEmpowering Growth with Best Software  Development Company in Noida - Deuglo
Empowering Growth with Best Software Development Company in Noida - Deuglo
Deuglo Infosystem Pvt Ltd
 
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Łukasz Chruściel
 
Launch Your Streaming Platforms in Minutes
Launch Your Streaming Platforms in MinutesLaunch Your Streaming Platforms in Minutes
Launch Your Streaming Platforms in Minutes
Roshan Dwivedi
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
Octavian Nadolu
 
E-commerce Application Development Company.pdf
E-commerce Application Development Company.pdfE-commerce Application Development Company.pdf
E-commerce Application Development Company.pdf
Hornet Dynamics
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
Paco van Beckhoven
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
Adele Miller
 
APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)
Boni García
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
Max Andersen
 
What is Augmented Reality Image Tracking
What is Augmented Reality Image TrackingWhat is Augmented Reality Image Tracking
What is Augmented Reality Image Tracking
pavan998932
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
Shane Coughlan
 
SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024
Hironori Washizaki
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
Aftab Hussain
 
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI AppAI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
Google
 
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
Łukasz Chruściel
 

Recently uploaded (20)

Transform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR SolutionsTransform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR Solutions
 
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket ManagementUtilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
 
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
 
Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
 
Empowering Growth with Best Software Development Company in Noida - Deuglo
Empowering Growth with Best Software  Development Company in Noida - DeugloEmpowering Growth with Best Software  Development Company in Noida - Deuglo
Empowering Growth with Best Software Development Company in Noida - Deuglo
 
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
 
Launch Your Streaming Platforms in Minutes
Launch Your Streaming Platforms in MinutesLaunch Your Streaming Platforms in Minutes
Launch Your Streaming Platforms in Minutes
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
 
E-commerce Application Development Company.pdf
E-commerce Application Development Company.pdfE-commerce Application Development Company.pdf
E-commerce Application Development Company.pdf
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
 
APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
 
What is Augmented Reality Image Tracking
What is Augmented Reality Image TrackingWhat is Augmented Reality Image Tracking
What is Augmented Reality Image Tracking
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
 
SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
 
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI AppAI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
 
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
 

10 Code Anti-Patterns to Avoid in Software Development.pdf

  • 1. 10 Code Anti-Patterns to Avoid in Software Development By: Ahmed Salama
  • 2. Intro The general performance, maintenance, and scalability of an application or system depend highly on the code structure. Unfortunately, due to the complex nature of software development, developers working on an application might resolve to use anti-patterns as a quick solution to a problem. Unfortunately, most of these anti-patterns end up causing problems to the general functionality of an application and future code maintenance. Here are 10 code anti-patterns you should avoid in software development: 1. The Golden Hammer 2. Spaghetti Code 3. Reinventing the Wheel 4. Dependency Hell 5. God Object or God Class 6. Hard Coding 7. Boat Anchor 8. Lava Flow 9. Copy – Paste Programming 10. Cargo – Cult Programming
  • 3. Intro ● In other words, anti-patterns might look like a good solution at first but eventually turn out to be the opposite, doing more harm than good. ● Anti-patterns have a negative impact on your software. They either introduce more bugs, raise security issues, or hinder code readability and maintenance. Below are ten code anti-patterns that will help you improve how you write your code.
  • 4. 1- The Golden Hammer ● This anti-pattern is a well-known solution in software development and is commonly used to make the development process much faster. It refers to the concept of using the same solution used to solve problem “A” to solve problem “B.” ● In software development, every problem has a unique solution. Always remember to choose the right tools, libraries, frameworks, and architecture for every problem. It is always recommended to come up with at least two solutions for each problem. Weigh the pros and cons of each before deciding to implement one that you find suitable.
  • 5. 2- Spaghetti Code ● Have you ever looked at a plate of spaghetti and just observed how each spaghetti is tangled and jumbled with each other? You can’t even know the start or the end of every spaghetti. Well, in software development, it is not a surprise to come across code similar to that. ● Most applications today are a victim of this. It mainly arises when a developer starts working on a project before taking note of the program flow and understanding the documentation well. ● Things become worse as your program grows. Your already messy code becomes messier. You start having multiple functions in different files invoking each other. You start copying and pasting a piece of already working code to solve a problem in a different part of your application. Whenever you delete a single function, half of the application breaks.
  • 6. 3- Reinventing the Wheel ● A scenario where developers opt to come up with a custom solution instead of using the existing solution in the market with the help of API and libraries. ● Think of a company that wants to add a blog/posts page on its website. It will take time and resources if developers decide to develop a custom CMS (Content Management System) from scratch. Instead, they can opt for already existing solutions such as WordPress, Joomla, and even headless CMS like Strapi, Ghost, or Contentful.
  • 7. 4- Dependency Hell ● In most cases, when you focus much on avoiding “Reinventing the Wheel,” you will most likely fall into the “dependency hell.” Instead of developers developing custom solutions, they import many third-party libraries into their projects. Unfortunately, some of these libraries also rely on other external libraries. ●
  • 8. 5- God Object or God Class ● This anti-pattern goes against the Principle of Single Responsibility in programming. According to this principle, every class should only have a single responsibility or single purpose in your project. ● This issue arises when developers ignore creating additional classes during the project’s initial phase and plan to do that later. Unfortunately, they continue adding more responsibilities to the initial class that even other functions and methods depend solely on. In most cases, it is perceived as the application’s main class. ● Ex: guest_email_settings, guest_sms_settings
  • 9. 6- Hard Coding ● This anti-pattern is most common in web development. A developer directly adds various parameters into the source code instead of fetching them from, say, a database, API, user input, the ‘.env’ file, etc. ● Two main issues arise with this anti-pattern. The first is security. If you hardcode an authentication parameter such as an API access token or JWT token, somebody can easily access it by just viewing the source code from the browser. ● The other issue is environmental change. When you hardcode parameters when working in “development,” your application will work perfectly. However, the application breaks when you push the changes to the “production” environment. You will need to edit the source code every time to suit every environment.
  • 10. 7- Boat Anchor ● This anti-pattern mainly arises when developers code an application with the “what if” question in mind. What if I need to add this functionality in the future? What if this particular scenario occurs in my code while in production? What if a user tries to access this feature? ● With all these “what if” questions in mind, developers eventually write additional lines of code not needed by the application at that particular moment. According to them, these extra lines might become helpful in the future. Unfortunately, this anti-pattern does more harm than good. ● This “unneeded” code becomes like a “boat anchor” It does nothing as of that moment, but your application still has to carry it because you think you might require that code in the future.
  • 11. 8- Lava Flow ● Lava flow anti-pattern refers to the concept where developers have to deal with redundant or low-quality code but appears to have a role in the general working of the application. Removing or editing this code becomes quite risky since you are unaware of what will happen to the app. ● Most of these issues arise from legacy code written during the project’s initial phase. Maybe the developer did not follow the documentation, or the project was moving too fast, and they didn’t have time to optimize and refactor the code. ● The best solution to lava flows is extensive testing and refactoring. Unfortunately, it’s easier said than done. Developers will spend much time trying to understand the code, and they might end up leaving it as it is for fear of breaking the application.
  • 12. 9- Copy – Paste Programming ● most copy and paste code snippets from stack overflow, GitHub, blogs, and youtube videos. ● Unfortunately, most developers don’t analyze the impact of this copy-pasted code; the only thing that matters is that “it works!” ● You should test this copied code very well and make sure it covers all your test cases!
  • 13. 10- Cargo – Cult Programming ● This anti-pattern derives its name from an interesting story. After the second world war, tribal societies from the south pacific came into contact with the advanced Western Civilization. It was the first time for the natives to see manufactured products such as radios, Coca-Cola, etc., brought to the island. ● Since they had never seen such things (cargo) before and didn’t understand how they were manufactured, they saw the Americans as gods. They started imitating whatever the Westerners were doing, hoping the gods would send more cargo to the island. That led to the rise of the name “cargo cults.”