Questions tagged [anti-patterns]

A programming anti-pattern is a commonly used solution to a specific programming problem, often claiming being an actual design pattern. But such a solution usually leads to adverse effects on an application scalability, testability and maintenance.

An anti-pattern can be thought of as a "worst of breed" solution to a problem in that it may "work" for its intended purpose, but have unwanted side effects or incur technical debt. Anti-patterns can arise from improper education, insufficient experience or simple ignorance.

SQL-Injection

In short, this is an anti-pattern of applying unfiltered user input directly to a database query string. This may seem like a quick and easy solution to querying data, however it can lead to data corruption, security breeches, and so-forth.

Example:

query-string = "select * from users where id='" + userid + "';"

Assuming the userid variable came directly from the user, an attacker can cause issues by setting the value to something that would cause unexpected behavior:

userid = "' or 1=1;drop table users"

Tight coupling

Instead of keeping two distinct parts of an application separate (CSS and HTML; Business Logic and the View in an MVC application), the parts are mingled such that a change in one necessitates a change in the other.

Example:

CSS

.yellow { color: yellow; }

HTML

<div class="yellow">foo</div>

In order to change the formatting, either the content (HTML) must be changed by substituting a different class name, or the class definition (CSS) must be changed to something that doesn't match its name.

Others

Wikipedia has other examples.

440 questions
28
votes
4 answers

How do you refactor a God class?

Does anyone know the best way to refactor a God-object? Its not as simple as breaking it into a number of smaller classes, because there is a high method coupling. If I pull out one method, i usually end up pulling every other method out.
Oliver Watkins
  • 12,575
  • 33
  • 119
  • 225
27
votes
6 answers

Concrete examples on why the 'Anemic Domain Model' is considered an anti-pattern

I apologize if this is a duplicate, but I couldn't find any concrete examples on the topic in related questions. After reading Martin Fowler's article on the 'Anemic Domain Model', I'm left wandering as to why is this considered an anti-pattern.…
27
votes
2 answers

Is passing around ActorRef to other Actors good or bad ?

I'm trying to figure out if my usage of passing Akka ActorRef around to other actors is not an anti-pattern. I've a few actors in my system. Some are long lived (restClientRouter,publisher) and some die after that they have done the work (geoActor).…
Soumya Simanta
  • 11,523
  • 24
  • 106
  • 161
26
votes
3 answers

Rich Domain Model and ORM

Martin Fowler considers Anemic Domain Model as an anti-pattern. Rolling the Persistence Model as the Domain Model seems severely off too due to Object Relational Impedence Missmatch. For persistence and normalization sakes, we tend to break down…
Alwyn
  • 8,079
  • 12
  • 59
  • 107
25
votes
6 answers

What are common antipatterns of using Git?

As a Git newbie, I realized that I have been using it as if it were Subversion. e.g. always working on master, not committing locally before pulling changes etc. This often results in avoidable manual merge situations. What are other common…
ottodidakt
  • 3,631
  • 4
  • 28
  • 34
24
votes
14 answers

What's the most unsound program you've had to maintain?

I periodically am called upon to do maintenance work on a system that was built by a real rocket surgeon. There's so much wrong with it that it's hard to know where to start. No, wait, I'll start at the beginning: in the early days of the…
Robert Rossney
  • 94,622
  • 24
  • 146
  • 218
22
votes
7 answers

What are the PHP-specific antipatterns that you know of?

PHP as a Blunt Instrument I hear PHP getting bashed around a lot lately. In quite a few projects, I have seen insane php code bases - so bad you really wonder if the person was on hallucinogenic drugs when they wrote the code. Sometimes, I wonder…
Elijah
  • 13,368
  • 10
  • 57
  • 89
22
votes
12 answers

Is returning an exception an anti-pattern?

I have two simple methods: public void proceedWhenError() { Throwable exception = serviceUp(); if (exception == null) { // do stuff } else { logger.debug("Exception happened, but it's alright.", exception) // do stuff …
Martin Linha
  • 979
  • 9
  • 21
22
votes
14 answers

Where did variable = null as "object destroying" come from?

Working on a number of legacy systems written in various versions of .NET, across many different companies, I keep finding examples of the following pattern: public void FooBar() { object foo = null; object bar = null; try { …
Paul Turner
  • 38,949
  • 15
  • 102
  • 166
20
votes
8 answers

Premature refactoring?

We have all heard of premature optimization, but what do you think about premature refactoring? Is there any such thing in your opinion? Here is what I am getting at. First off, reading Martin Fowler's seminal work "Refactoring" quite literally…
Swim
  • 1,561
  • 1
  • 12
  • 18
20
votes
6 answers

What are some examples of leap year bugs?

A leap year bug is a code defect that creates a problematic, unintended outcome when executed within the context of a leap year, typically within the proleptic Gregorian calendar system. The last leap year was 2016. The next leap years are 2020 and…
Matt Johnson-Pint
  • 230,703
  • 74
  • 448
  • 575
20
votes
0 answers

Why is a generic repository considered an anti-pattern?

it seems to me that a lot of specialised repository classes share similar characteristics, and it would make sense to have these classes implement an interface that outlines these characteristics, creating a generic repository to illustrate my…
user2541688
20
votes
15 answers

Misused design patterns

Are there, in the canonical Gang of Four list, any design patterns that you often find misused, misunderstood or overused (other than the highly debated Singleton)? In other words, is there a design pattern you would advise to think twice before…
Federico A. Ramponi
  • 46,145
  • 29
  • 109
  • 133
19
votes
13 answers

Is there a name for this anti-pattern/code smell?

Let me start by saying that I do not advocate this approach, but I saw it recently and I was wondering if there was a name for it I could use to point the guilty party to. So here goes. Now you have a method, and you want to return a value. You…
Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794
19
votes
3 answers

anemic domain model versus domain model

Being confused again after reading about this anti-pattern and the many concerns about it here on SO. If I have a domain model and capture the data that must be persisted in a data transfer object, does that make my domain model a wrapper around the…
1 2
3
29 30