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
65
votes
9 answers

Why is "element.innerHTML+=" bad code?

I have been told not to append stuff using element.innerHTML += ... like this: var str = "
hello world
"; var elm = document.getElementById("targetID"); elm.innerHTML += str; //not a good idea? What is wrong with it?, what other…
ajax333221
  • 11,436
  • 16
  • 61
  • 95
64
votes
10 answers

Singleton in go

How does one implement the Singleton design pattern in the go programming language?
Ben Noland
  • 34,230
  • 18
  • 50
  • 51
56
votes
10 answers

What anti-patterns exist for JavaScript?

I find that what not to do is a harder lesson to learn than what should be done. From my experience, what separates an expert from an intermediate is the ability to select from among various seemingly equivalent ways of doing the same thing. So,…
Allain Lalonde
  • 91,574
  • 70
  • 187
  • 238
55
votes
38 answers

C# Antipatterns

To cut a long story short: I find the Java antipatterns an indispensable resource. For beginners as much as for professionals. I have yet to find something like this for C#. So I'll open up this question as community wiki and invite everyone to…
exhuma
  • 20,071
  • 12
  • 90
  • 123
52
votes
13 answers

How to prevent the arrowhead anti-pattern

I'm a bit confused about how to best refactor my code into something more readable. Consider this piece of code: var foo = getfoo(); if(foo!=null) { var bar = getbar(foo); if(bar!=null) { var moo = getmoo(bar); …
Kippie
  • 3,760
  • 3
  • 23
  • 38
44
votes
14 answers

What is the name of this bad practice / anti-pattern?

I'm trying to explain to my team why this is bad practice, and am looking for an anti-pattern reference to help in my explanation. This is a very large enterprise app, so here's a simple example to illustrate what was implemented: public void…
John Cornell
  • 1,087
  • 8
  • 22
43
votes
21 answers

Embedded systems worst practices?

What would you consider "worst practices" to follow when developing an embedded system? Some of my ideas of what not to do are: Avoid abstracting the hardware layer, instead spreading hardware accesses throughout the code. Not having any type of…
Fred Basset
  • 1,147
  • 1
  • 12
  • 10
40
votes
8 answers

Ravioli code - why an anti-pattern?

I recently came across a term 'God object' which was described as an 'anti-pattern'. I'd heard of bad coding practices, but I'd never heard them described thus. So I headed off to Wikipedia to find out more, and I found that there is an anti-pattern…
Tola Odejayi
  • 3,019
  • 9
  • 31
  • 46
35
votes
6 answers

Avoiding parallel inheritance hierarchies

I have two parallel inheritance chains: Vehicle <- Car <- Truck <- etc. VehicleXMLFormatter <- CarXMLFormatter <- TruckXMLFormatter <- etc. My experience has been that parallel inheritance hierarchies can become a…
parkr
  • 3,188
  • 5
  • 35
  • 39
34
votes
13 answers

What is spaghetti code?

Can you post a short example of real, overdone spaghetti code, possibly saying what it does? Can you show me a little debugger's nightmare? I don't mean IOCCC code, that is science fiction. I mean real life examples that happened to…
Federico A. Ramponi
  • 46,145
  • 29
  • 109
  • 133
31
votes
6 answers

Dependency Injection best practices and anti-patterns

I'm relatively unskilled in Dependency Injection, and I'd like to learn some best practices and anti-patterns to use and avoid respectively when using DI.
ripper234
  • 222,824
  • 274
  • 634
  • 905
30
votes
3 answers

Is it an antipattern to use angular's $watch in a controller?

In my never ending quest to do things the "proper" angular way, I have been reading a lot about how to have controllers observe the changes in models held in angular services. Some sites say using a $watch on a controller is categorically…
tengen
  • 2,125
  • 3
  • 31
  • 57
30
votes
4 answers

the significance of java RMI please?

Why do people use RMI, or when should I use RMI? I read those tutorials about RMI on oracle's website. But it doesn't provide enough practical examples. To my understanding, software should have its modules as "unrelated and separated" as possible.…
28
votes
7 answers

Extending singletons in PHP

I'm working in a web app framework, and part of it consists of a number of services, all implemented as singletons. They all extend a Service class, where the singleton behaviour is implemented, looking something like this: class Service { …
Johan Fredrik Varen
  • 3,796
  • 7
  • 32
  • 42
28
votes
1 answer

Are there any documented anti-patterns for functional programming?

Next month I'm going to work on a new R&D project that will adopt a functional programming language (I voted for Haskell, but right now F# got more consensus). Now, I've played with such languages for a while and developed a few command line tools…
Giacomo Tesio
  • 7,144
  • 3
  • 31
  • 48
1
2
3
29 30