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.

421 questions
241
votes
39 answers

What are the most common SQL anti-patterns?

All of us who work with relational databases have learned (or are learning) that SQL is different. Eliciting the desired results, and doing so efficiently, involves a tedious process partly characterized by learning unfamiliar paradigms, and…
dkretz
  • 36,502
  • 13
  • 76
  • 133
229
votes
34 answers

What to do about a 11000 lines C++ source file?

So we have this huge (is 11000 lines huge?) mainmodule.cpp source file in our project and every time I have to touch it I cringe. As this file is so central and large, it keeps accumulating more and more code and I can't think of a good way to make…
Martin Ba
  • 33,741
  • 27
  • 150
  • 304
219
votes
14 answers

What is an anti-pattern?

I am studying patterns and anti-patterns. I have a clear idea about patterns, but I don't get anti-patterns. Definitions from the web and Wikipedia confuse me a lot. Can anybody explain to me in simple words what an anti-pattern is? What is the…
g.revolution
  • 10,884
  • 19
  • 74
  • 102
203
votes
31 answers

Unit testing Anti-patterns catalogue

anti-pattern : there must be at least two key elements present to formally distinguish an actual anti-pattern from a simple bad habit, bad practice, or bad idea: Some repeated pattern of action, process or structure that initially appears to be…
Gishu
  • 126,803
  • 45
  • 214
  • 298
155
votes
20 answers

Singleton with Arguments in Java

I was reading the Singleton article on Wikipedia and I came across this example: public class Singleton { // Private constructor prevents instantiation from other classes private Singleton() {} /** * SingletonHolder is loaded on…
Scott
148
votes
8 answers

Is ServiceLocator an anti-pattern?

Recently I've read Mark Seemann's article about Service Locator anti-pattern. Author points out two main reasons why ServiceLocator is an anti-pattern: API usage issue (which I'm perfectly fine with) When class employs a Service locator it is very…
140
votes
11 answers

Why are data transfer objects (DTOs) an anti-pattern?

I've recently overheard people saying that data transfer objects (DTOs) are an anti-pattern. Why? What are the alternatives?
ntownsend
  • 6,884
  • 9
  • 35
  • 34
128
votes
8 answers

Any reason not to use '+' to concatenate two strings?

A common antipattern in Python is to concatenate a sequence of strings using + in a loop. This is bad because the Python interpreter has to create a new string object for each iteration, and it ends up taking quadratic time. (Recent versions of…
Taymon
  • 22,123
  • 8
  • 58
  • 80
107
votes
12 answers

Design patterns to avoid

A lot of people seem to agree, that the Singleton pattern has a number of drawbacks and some even suggest avoiding the pattern entirely. There's an excellent discussion here. Please direct any comments about the Singleton pattern to that question.…
Brian Rasmussen
  • 109,816
  • 33
  • 208
  • 305
90
votes
4 answers

Why is "log and throw" considered an anti-pattern?

This question was sparked by a discussion around this article, where I did not receive any good answers. Why should logging your exception and then rethrowing it (preserving the original stack trace of course) be a bad idea if you can't handle it…
Manu
  • 27,156
  • 27
  • 70
  • 82
88
votes
4 answers

Why is Singleton considered an anti-pattern?

Possible Duplicate: What is so bad about Singletons? Singleton Design Pattern: Pitfalls Singleton anti-pattern I've heard recently that Singleton is an anti-pattern. I know it has to do with the fact making a class singleton is like making that…
user1710031
  • 951
  • 2
  • 8
  • 7
76
votes
37 answers

What is the most EVIL code you have ever seen in a production enterprise environment?

What is the most evil or dangerous code fragment you have ever seen in a production environment at a company? I've never encountered production code that I would consider to be deliberately malicious and evil, so I'm quite curious to see what…
Registered User
  • 8,079
  • 8
  • 44
  • 62
72
votes
7 answers

Python: is using "..%(var)s.." % locals() a good practice?

I discovered this pattern (or anti-pattern) and I am very happy with it. I feel it is very agile: def example(): age = ... name = ... print "hello %(name)s you are %(age)s years old" % locals() Sometimes I use its cousin: def…
flybywire
  • 232,954
  • 184
  • 384
  • 491
69
votes
7 answers

Are subversion externals an antipattern?

Subversion lets you embed working copies of other repositories using externals, allowing easy version control of third-party library software in your project. While these seem ideal for the reuse of libraries and version control of vendor software,…
Ken
  • 71,088
  • 29
  • 81
  • 100
63
votes
8 answers

How to block users from closing a window in Javascript?

Is it possible to block users from closing the window using the exit button [X]? I am actually providing a close button in the page for the users to close the window.Basically what I'm trying to do is to force the users to fill the form and submit…
manraj82
  • 4,809
  • 23
  • 53
  • 83
1
2 3
28 29