{"id":6434,"date":"2022-08-29T14:58:35","date_gmt":"2022-08-29T14:58:35","guid":{"rendered":"https:\/\/www.modernescpp.com\/index.php\/anti-patterns\/"},"modified":"2023-06-26T09:01:36","modified_gmt":"2023-06-26T09:01:36","slug":"anti-patterns","status":"publish","type":"post","link":"https:\/\/www.modernescpp.com\/index.php\/anti-patterns\/","title":{"rendered":"Anti-Patterns"},"content":{"rendered":"<p>An anti-pattern is a proven way to shoot yourself into your foot. The term anti-pattern was coined by<a href=\"https:\/\/en.wikipedia.org\/wiki\/Andrew_Koenig_(programmer)\"> Andrew Koenig<\/a>, and it is pretty entertaining to read about them.<\/p>\n<p><!--more--><\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-6433\" src=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2022\/08\/AntiPatterns1.png\" alt=\"AntiPatterns\" width=\"650\" height=\"327\" style=\"display: block; margin-left: auto; margin-right: auto;\" srcset=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2022\/08\/AntiPatterns1.png 1215w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2022\/08\/AntiPatterns1-300x151.png 300w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2022\/08\/AntiPatterns1-1024x515.png 1024w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2022\/08\/AntiPatterns1-768x386.png 768w\" sizes=\"auto, (max-width: 650px) 100vw, 650px\" \/><\/p>\n<p>The book &#8220;<a href=\"https:\/\/en.wikipedia.org\/wiki\/Design_Patterns\">Design Patterns: Elements of Reusable Object-Oriented Software<\/a>&#8221; (Design Patterns), published in 1994, defined Anti-Patterns as a &#8220;<em>commonly-used process, structure or pattern of action that, despite initially appearing to be an appropriate and effective response to a problem, has more bad consequences than good ones<\/em>.&#8221; In 1998, the book &#8220;<a href=\"https:\/\/en.wikipedia.org\/wiki\/AntiPatterns\">AntiPatterns: Refactoring Software, Architectures, and Projects in Crisis<\/a>&#8221; (AntiPatterns) made the term popular. This book defined Anti-Patterns as &#8220;<em>specific repeated practices in software architecture, software design and software project management that initially appear to be beneficial, but ultimately result in bad consequences that outweigh hoped-for advantages.&#8221;&nbsp;<\/em><\/p>\n<p>To make it short, <strong>an Anti-Pattern is a commonly used practice providing more bad consequences than good ones<\/strong>.<\/p>\n<p>The following paragraph provides a few theories about Anti-Patterns in a very concise way. This theory is based on the book &#8220;<a href=\"https:\/\/en.wikipedia.org\/wiki\/AntiPatterns\">AntiPatterns: Refactoring Software, Architectures, and Projects in Crisis<\/a>&#8220;. For more detailed information, read the quoted book.<\/p>\n<\/p>\n<h2>AntiPatterns: Refactoring Software, Architectures, and Projects in Crisis<\/h2>\n<p>An Anti-Pattern is similar to a Design Pattern, a literary form, and simplifies the communication and problem description of a commonly occurring problem. Often, it is a pattern applied in the wrong context. Here are the main causes. The seven sins of software development:<\/p>\n<ul>\n<li><span class=\"toctext\">Lust<\/span><\/li>\n<li><span class=\"toctext\">Gluttony<\/span><\/li>\n<li><span class=\"toctext\">Greed<\/span><\/li>\n<li><span class=\"toctext\">Sloth<\/span><\/li>\n<li><span class=\"toctext\">Wrath<\/span><\/li>\n<li><span class=\"toctext\">Envy<\/span><\/li>\n<li><span class=\"toctext\">Pride<\/span><\/li>\n<\/ul>\n<p>On the contrary, the software design has to consider the following elementary forces when making decisions.<\/p>\n<ul>\n<li>Functionality management<\/li>\n<li>Performance management (non-functional requirements)<\/li>\n<li>Complexity management<\/li>\n<li>Change management<\/li>\n<li>IT resources management<\/li>\n<li>Technology transfer management<\/li>\n<\/ul>\n<p>Each Anti-Pattern has the following three components:<\/p>\n<ul>\n<li>Name: unique name with a negative connotation<\/li>\n<li>Problem: commonly used practice with bad consequences<\/li>\n<li>Refactoring: avoidance of the Anti-Pattern or minimization of its impact<\/li>\n<\/ul>\n<p>The book AntiPatterns presents three typical domains:<\/p>\n<ol>\n<li><strong>Software Development<\/strong>: An appropriate software structure is essential for system extension and maintenance, but software development is often a chaotic activity. Software refactoring is the key to improving software structure.<\/li>\n<li><strong>Software Architecture<\/strong>: Architecture focuses on the system-level and enterprise-level structure of the system. Good architecture is the key factor to the success of system development and can be achieved by architecture-driven software development.<\/li>\n<li><strong>Project Management<\/strong>: Modern software engineering depends mainly on human communication. Bad project management can be highly destructive to software processes. The solutions to the Anti-Patterns are to eliminate unproductive boundaries and empower the engineers to make their own decisions.<\/li>\n<\/ol>\n<p>Now, to the fun part. Here are a few Anti-Patterns. I use the classification of the Anti-Patterns book but also incorporate anti-patterns from other sources. Additionally, I present a few reasons for the presented anti-patterns.<\/p>\n<h2>Software Development Anti-Pattern<\/h2>\n<ul>\n<li><strong>Cut-and-paste programming<\/strong> (aka copy-and-paste): Code reused by copying source statements leads to significant maintenance problems. (from AntiPatterns). The reason may be that the company has no code reuse culture. Also, a lack of abstraction or missing communication may be the cause.<\/li>\n<li><strong>Lava flow<\/strong> (aka dead code): Dead code and forgotten design information are frozen in an ever-changing design (from AntiPatterns). The emphasis lies in the development of new features. There is no time for code refactoring.<\/li>\n<li><strong>Onion<\/strong>: new code is wrapped around the old one. It is often easier to add an additional layer of abstraction than to refactor the software and improve its internal structure.(<a href=\"https:\/\/de.wikipedia.org\/wiki\/Anti-Pattern\">https:\/\/de.wikipedia.org\/wiki\/Anti-Pattern<\/a>)<\/li>\n<li><strong>Swiss army knife <\/strong>(aka kitchen sink): The One-Tool Wonder is a universal solution to all needs; a panacea (from AntiPatterns). This Anti-Pattern is strongly related to the golden hammer syndrome.<\/li>\n<li><strong>Golden hammer<\/strong>: (aka head-in-the-sand) A Golden Hammer is a familiar technology or concept applied obsessively to many software problems (from AntiPatterns) A lack of knowledge of alternative strategies is the main reason. Also, the previous solutions worked out very well and are applied once more.<\/li>\n<\/ul>\n<h2>Software Architecture Anti-Pattern<\/h2>\n<ul>\n<li><strong>The god class <\/strong>(the blob): A &#8220;God Class&#8221; is an object that controls way too many other objects in the system and has grown beyond all logic to become The Class That Does Everything. (<a href=\"https:\/\/wiki.c2.com\/?GodClass\">https:\/\/wiki.c2.com\/?GodClass<\/a>). It&#8217;s often easier to just add a member function to a class than to make a design decomposition.<\/li>\n<li><strong>Spaghetti code:<\/strong> Spaghetti code is a pejorative phrase for unstructured and difficult-to-maintain source code. (<a href=\"https:\/\/en.wikipedia.org\/wiki\/Spaghetti_code\">https:\/\/en.wikipedia.org\/wiki\/Spaghetti_code<\/a>). The obvious reason is the overuse of <code>GOTO<\/code> statements, exception handling, or deeply nested<code> if-else<\/code> structures. Lack of abstraction and architectural decomposition is the main cause.<\/li>\n<li><strong>&nbsp;Big ball of mud<\/strong>: a software system that lacks a perceivable architecture (<a href=\"https:\/\/en.wikipedia.org\/wiki\/Big_ball_of_mud\">https:\/\/en.wikipedia.org\/wiki\/Big_ball_of_mud<\/a>). A typical reason is a time and feature-driven design.<\/li>\n<\/ul>\n<h2>Project Management Anti-Pattern<\/h2>\n<ul>\n<li><strong>Brook&#8217;s law<\/strong>: adding manpower to a late software project makes it later. (<a href=\"https:\/\/en.wikipedia.org\/wiki\/Brooks%27s_law\">https:\/\/en.wikipedia.org\/wiki\/Brooks%27s_law<\/a>). New people slow down the development process because they have to be trained by experienced developers.<\/li>\n<li><strong> Death march<\/strong>: a project that participants believe is destined for failure or that requires a stretch of unsustainable overwork (<a href=\"https:\/\/en.wikipedia.org\/wiki\/Death_march_\">https:\/\/en.wikipedia.org\/wiki\/Death_march_<\/a>(project_management). The company&#8217;s culture is based on control but not on trust. Contrary opinions are not accepted.<\/li>\n<li><strong>Mushroom management<\/strong>: &#8220;Keep them in the dark and feed them full of shit.\u201d&nbsp;In some architecture and management circles, there is an explicit policy to keep system developers isolated from the system\u2019s end users.(from, AntiPatterns) The company&#8217;s culture is based on control but not on trust.<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<h2>What&#8217;s next?<\/h2>\n<p>In my upcoming post, I will write about classic design patterns. First, I write about the creational patterns<\/p>\n<p>&nbsp;<\/p>\n<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>An anti-pattern is a proven way to shoot yourself into your foot. The term anti-pattern was coined by Andrew Koenig, and it is pretty entertaining to read about them.<\/p>\n","protected":false},"author":21,"featured_media":6433,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[379],"tags":[410],"class_list":["post-6434","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-patterns","tag-anti-patterns"],"_links":{"self":[{"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/posts\/6434","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/users\/21"}],"replies":[{"embeddable":true,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/comments?post=6434"}],"version-history":[{"count":1,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/posts\/6434\/revisions"}],"predecessor-version":[{"id":6662,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/posts\/6434\/revisions\/6662"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/media\/6433"}],"wp:attachment":[{"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/media?parent=6434"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/categories?post=6434"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/tags?post=6434"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}