tectera.com

What’s An Anti-pattern?

An antipattern is a well-known but unsuccessful solution to a problem in web development or software development. Antipatterns are also referred to as failure patterns. In other words, it refers to situations in which developers generate solutions that are more destructive than the problems, which most often occurs when a good software development technique is lacking. The good news is that they can be identified and avoided.  This sense of self-criticism in programming requires the capacity to spot unproductive or counter-productive patterns in design, code, procedures, and behavior. This is why understanding anti-patterns are extremely beneficial to any developer.

In this blog, we’ll look at 23 common coding antipatterns in web development that can lead us to believe our code is well-optimized.

1.      Spaghetti Code

The most well-known coding antipattern is “spaghetti code.” It refers to a program that is difficult to debug or modify due to a lack of appropriate architecture. Poor software design results in a tangle of code that resembles a dish of spaghetti in structure, i.e.twisted and complex. The readability of spaghetti code is exceedingly low, and understanding how it works is frequently a near-impossible task.

Spaghetti code is usually the result of a combination of bad coding practices, such as the lack of proper conditionals blocks, the use of a lot of go-to statements, exceptions, and threads, the inclusion of parts that belong somewhere else, the use of minimal relationships between objects, the use of functions, and the lack of documentation.

2.      Analysis Paralysis

Analysis Paralysis is over-analyzing to the point where action and progress are hampered. It’s problematic because over-analyzing can stifle or even halt progress. In the worst-case scenario, the analysis results may become obsolete by the time they complete it or the project may never exit the analysis phase. When making a difficult decision during web development, it’s also natural to assume that more knowledge will aid decision-making.

To avoid this, we should emphasize iterations and improvements. Each repetition will provide more data points and feedback, allowing for more meaningful analysis. More analysis will become increasingly speculative in the absence of additional data points.

3.      Bikeshedding

Bikeshedding is the tendency to waste a lot of time debating and making decisions about little and often subjective problems. It’s something we should avoid because it’s a waste of time. As a result, encourage team members to be aware of this propensity and to make a decision as soon as they observe it. When it’s time to review the decision, A/B testing might be a good idea.

The tough aspect is that, in my perspective, bikeshedding is easier to detect and prevent than premature optimization. Simply keep track of how much time you spend making decisions and compare it to how little the problem is, and intervene if necessary.

4.      Golden Hammer

The Golden Hammer antipattern refers to the tendency to rely too heavily on a particular technique or tool when undertaking web development, rather than using a variety of tools that would be more relevant for the work at hand. This can lead to major problems with performance and upkeep.

Different languages have their own norms and solutions to the difficulties they confront. You can’t just apply every rule that worked for you in one language to the next without problems. In your career, don’t forget to keep learning. Choose the appropriate language for your situation. Consider the architecture and get outside of your comfort zone. Investigate new tools and approaches to the difficulties you’re dealing with.

5.      Premature Optimization

Good timing is a crucial factor in code optimization. We can easily reproduce the antipattern of “premature optimization” if we pay attention to small efficiencies and optimize for them too early in the development process before we exactly know what we want to do.

If we optimize for performance before setting up an effective architecture, we may lower code readability, make debugging and maintenance harder, and add superfluous parts to our code.

To prevent premature optimization, it’s a good idea to always implement things when you actually need them, not when you just foresee that you need them.

6.      Reinvent the Wheel

The Reinvent the Wheel antipattern is an example of attempting to reinvent something that already exists rather than reusing it. This might result in many instances of the same program, defective code, performance issues, and other issues.

7.      God Object and God Class

God Classes are classes that have a lot of dependents and responsibilities and control a lot of other classes. Because they violate the single-responsibility principle and are difficult to unit-test, debug, and document, they tend to expand to the point of being maintenance nightmares.

By dividing out the tasks into smaller classes with a single well-defined, unit-tested, and documented role, we can avoid classes becoming God classes. The problematic aspect is that, as Web development continues and requirements and the number of engineers increases, modest, well-intentioned classes gradually transform into God classes. Refactoring such classes can be time-consuming.

8.      Boat Anchor

When someone tries to employ an unnecessarily sophisticated or over-engineered solution instead of a simpler one that would have worked just as well or better in the first place, the Boat Anchor antipattern develops. It alludes to wasting too much time creating something elaborate when all you actually wanted was a simple table anchor for your boat hence the term “boat anchor.”

Attempting to handle too many problems at once or by making it too broad and intricate complicates this type of solution , resulting in a solution that solves a basic problem in a complicated manner.

9.      Dependency Shell

When you start dragging around too much baggage, something like a dependence shell can happen. It refers to incorporating extra dependencies for a web development that you don’t really require merely because someone else does. This frequently results in larger files, bloated packages, more testing, and other issues, all of which might make future updates difficult or impossible.

10.  Programming by Permutation

Whenever we try to solve a problem by sequentially experimenting with little alterations, testing and assessing them one by one, and then implementing the one that works at first, we call this “programming by permutation” or “programming by accident.” Permutation programming can readily add new defects to our code, and they’re bugs we don’t always see right away. In many circumstances, it’s also hard to predict whether or not a solution would work in all scenarios.

11.  Fear of Adding Classes

The dread of adding classes stems from the notion that adding more classes will inevitably complicate designs, leading to a fear of adding additional classes or dividing large classes into multiple smaller classes. It’s a problem because Adding classes can significantly reduce complexity. Consider a tangled ball of strands. Instead of one tangled yarn, you’ll get multiple untangled skeins. Similarly, several small, easy-to-maintain, and easy-to-document classes are preferable than a single huge, complex class with multiple responsibilities. You can avoid it by recognizing when new classes can simplify the design and disconnect needlessly connected code.

12.  Dead Code

Have you ever had to review code created by someone who is no longer employed in your company? There’s a feature that doesn’t appear to be doing anything. When you ask around, no one else knows what it’s doing, but no one is willing to delete it. You can see what it’s doing sometimes, but the context is lacking. You can read and comprehend the flow, but why? We don’t appear to need to reach that route any longer. For each and every user, the response is the same.

The Dead Code anti-pattern is a term used to characterize this behavior. When you can’t tell what “real” code is required for the flow and proper execution of your program, as opposed to what was required three years ago but is no longer required. This anti-pattern is more common in proof-of-concept or research code that has made its way into production.

13.  Inner-platform Effect

The inner-platform effect refers to the tendency of complicated software systems to re-implement characteristics of the platform on which they operate or the programming language in which they are written, frequently in a poor manner. Because platform-level chores like job scheduling and disc cache buffers are difficult to do correctly, it’s problematic.

Poorly conceived solutions are more likely to introduce bottlenecks and issues as the system grows larger. Furthermore, developing alternative language structures to achieve what is already achievable in the language results in code that is difficult to comprehend and a steeper learning curve for anyone new to the code base. It can also make refactoring and code analysis tools less useful.

14.  Copy and Paste Programming

When we don’t follow the Don’t Repeat Yourself (DRY) coding concept, we get “copy and paste programming.” Rather than providing generic solutions, we paste pre-existing code snippets into various locations and then tweak them to fit the context. Because the substituted code segments normally only differ in minor differences, this method results in a code that is excessively repetitive.

Not just new developers, but also experienced programmers, are guilty of copy and paste programming. Since many of them are prone to utilizing their own pre-written, well-tested code snippets for certain tasks. This can easily lead to accidental repeats.

15.  Proliferation of Code

Objects and modules interact with each other on a regular basis. You’ll frequently need to call into other separate modules and call new functions if your codebase is clean and modularized. When you have objects in your codebase that only exist to execute another, more essential object, you have the Proliferation of Code anti-pattern.

When you have objects in your codebase that only exist to invoke a more significant object, this is known as the Proliferation of Code anti-pattern. Its sole function is to act as a link between two parties. This adds an unneeded layer of abstraction (something to memorize) and serves no purpose other than to confuse individuals who need to comprehend your codebase’s flow and execution. Simply removing it is a straightforward solution here. Charge the caller object with invoking the item you truly desire.

16.  Cargo-Cult Programming

The Cargo-Cult programming antipattern occurs when you follow code methods or patterns that don’t make sense or operate properly. It’s frequently based on replicating what someone else has done without fully comprehending why it’s done that way. This can lead to a slew of issues in the future.

17.  Lava Flow

When you have too many changes happening in your codebase at the same time, you get the Lava Flow antipattern. This can make it difficult to pinpoint the root of a problem, or cause distinct components of the software to no longer work in harmony with one another. Cleaning up can be a nightmare.

In theory, comprehensive testing and refactoring can eliminate lava flows, but in reality, implementation is often difficult, if not impossible. Because lava flows have such significant performance costs, it’s better to avoid them from the beginning by building a well-designed architecture and a sound workflow.

18.  Hard Coding

Hard coding” is a well-known antipattern that most web development books warn us about right up front. It is the undesirable habit of storing configuration or input data in source code rather than acquiring it from a configuration file, a database, user input, or another external source, such as a file path or a remote host name.

The biggest issue with hard code is that it only functions in a specific environment, and if those conditions change, we must update the source code, which is normally done in numerous locations.

19.  Soft Coding

Even if we strive very hard to avoid the mistake of hard coding, we might easily fall victim to another antipattern known as “soft coding,” which is the polar opposite of hard coding. Soft coding involves putting items that should be in the source code into external sources, such as the database, where business logic is stored. The most typical reason for this is that we are afraid that business regulations will change in the future, necessitating rewriting the code.

A soft-coded web development software can grow so complex and convoluted in extreme circumstances that it is nearly impossible to understand. Especially for new team members. They’re also exceedingly difficult to maintain and debug.

20.  Error Hiding and Exception Swallowing

The antipatterns of Error concealing and Exception swallowing are two related code issues that can create major troubles down the road. You try to hide errors from the user by presenting a nice message instead of the actual error code with error hiding. This can be useful in some situations, but it’s not a viable long-term answer.

When you catch an exception and then do nothing with it, you’re effectively “swallowing” it and pretending it never happened. This can potentially lead to several other issues in the future.

21.  Management by Numbers

When managers rely too heavily on quantitative rather than comprehending how the web development software works, the Management by Numbers antipattern occurs. For example, if a manager examines your code and discovers that it takes an average of five minutes to execute a request, they may pressure you to boost the speed by 50% to reduce the time required. This is a gross simplification of how algorithms work, and it could lead to many issues in the future.

22.  Useless (Poltergeist) Classes

Classes that are useless (Poltergeist) are classes that have no genuine responsibilities of their own. They’re frequently used to invoke methods from another class or to add an unnecessary layer of abstraction. Poltergeist classes add complexity, extra code to maintain and test, and make the code less accessible to the reader. The reader must first understand what the poltergeist does. Which is often absolutely nothing and then mentally replace the poltergeist with the class that performs the job.

These can be avoided by either not writing pointless classes or refactoring them out.

23.  Magic Numbers and Strings

It’s basically replacing named constants in code with nameless numbers or string literals. The major issue is that without a descriptive label or some type of annotation, the semantics of the number or string literal are partially or totally concealed. This makes it more difficult to comprehend the code. The constant needs to be changed, search and replace or other refactoring tools can introduce minor issues. Using named constants, resource retrieval methods, or annotations can help you avoid this.

 

sales@tectera.com
0774332205
Phone
Email