Questions tagged [anti-patterns]

An anti-pattern is a behavior or practice that is common despite being ineffective or counterproductive.

In software engineering, an anti-pattern (or antipattern) is a pattern that may be commonly used but is ineffective and/or counterproductive in practice.

The term was coined in 1995 by Andrew Koenig, inspired by Gang of Four's book Design Patterns, which developed the concept of design patterns in the software field. The term was widely popularized three years later by the book AntiPatterns, which extended the use of the term beyond the field of software design and into general social interaction. According to the authors of the latter, 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 beneficial, but ultimately produces more bad consequences than beneficial results, and
  • An alternative solution exists that is clearly documented, proven in actual practice and repeatable.

(excerpted from the Wikipedia article)

235 questions
610
votes
13 answers

So Singletons are bad, then what?

There has been a lot of discussion lately about the problems with using (and overusing) Singletons. I've been one of those people earlier in my career too. I can see what the problem is now, and yet, there are still many cases where I can't see a…
234
votes
10 answers

Is there a name for the (anti- ) pattern of passing parameters that will only be used several levels deep in the call chain?

I was trying to find alternatives to the use of global variable in some legacy code. But this question is not about the technical alternatives, I'm mainly concerned about the terminology. The obvious solution is to pass a parameter into the…
RubenLaguna
  • 1,842
  • 2
  • 12
  • 11
223
votes
7 answers

What is wrong with magic strings?

As an experienced software developer, I have learned to avoid magic strings. My problem is that it is such a long time since I have used them, I've forgotten most of the reasons why. As a result, I'm having trouble explaining why they're a problem…
Kramii
  • 14,029
  • 5
  • 44
  • 64
200
votes
10 answers

Are exceptions as control flow considered a serious antipattern? If so, Why?

Back in the late 90's I worked quite a bit with a code base that used exceptions as flow control. It implemented a finite state machine to drive telephony applications. Lately I am reminded of those days because I've been doing MVC web apps. They…
Aaron Anodide
  • 5,463
  • 5
  • 28
  • 37
150
votes
13 answers

Is using nested try-catch blocks an anti-pattern?

Is this an antipattern? It is an acceptable practice? try { //do something } catch (Exception e) { try { //do something in the same line, but being less ambitious } catch (Exception ex) { try…
Mister Smith
  • 2,867
  • 4
  • 21
  • 17
135
votes
27 answers

Is source code generation an anti-pattern?

If something can be generated, then that thing is data, not code. Given that, isn't this whole idea of source code generation a misunderstanding? That is, if there is a code generator for something, then why not make that something a proper function…
Utku
  • 1,922
  • 4
  • 17
  • 19
115
votes
17 answers

Why should 'boneheaded' exceptions not be caught, especially in server code?

I am confused because in quite a few places I've already read that the so-called 'boneheaded' exceptions (ones that result from bugs in code) are not supposed to be caught. Instead, they must be allowed to crash the application: Vexing exceptions,…
gaazkam
  • 3,517
  • 3
  • 19
  • 35
104
votes
11 answers

What's the name of the antipattern opposite to "reinventing the wheel"?

The "Reinvent the wheel" antipattern is a pretty common one - instead of using a ready solution, write your own from scratch. Code base grows needlessly, slightly different interfaces that do the same thing but slightly differently abound, time is…
SF.
  • 5,078
  • 2
  • 24
  • 36
101
votes
9 answers

Is putting general-use functions in a "helpers" file an anti-pattern or code smell?

Is it an anti-pattern or code smell to put "general use" functions (examples below) into a catch-all file named "helpers" or "utils"? It's a pattern I've seen quite a lot in the JavaScript world, which I've also seen with other languages. By…
old greg
  • 909
  • 2
  • 4
  • 6
101
votes
60 answers

Which things instantly ring alarm bells when looking at code?

I attended a software craftsmanship event a couple of weeks ago and one of the comments made was "I'm sure we all recognize bad code when we see it" and everyone nodded sagely without further discussion. This sort of thing always worries me as…
FinnNk
  • 5,799
  • 3
  • 28
  • 32
99
votes
34 answers

"Comments are a code smell"

A coworker of mine believes that any use of in-code comments (ie, not javadoc style method or class comments) is a code smell. What do you think?
Fishtoaster
  • 25,909
  • 15
  • 111
  • 154
86
votes
7 answers

EAV - is it really bad in all scenarios?

I'm thinking to use an entity-attribute-value (EAV) model for some of the stuff in one of the projects, but all questions about it in Stack Overflow end up to answers calling EAV an anti-pattern. But I'm wondering if it is that wrong in all…
Giedrius
  • 1,304
  • 1
  • 10
  • 15
80
votes
8 answers

Is modifying an incoming parameter an antipattern?

I am programming in Java, and I always make converters sort of like this: public OtherObject MyObject2OtherObject(MyObject mo){ ... Do the conversion return otherObject; } At the new workplace the pattern is: public void…
72
votes
14 answers

Name for this antipattern? Fields as local variables

In some code I'm reviewing, I'm seeing stuff that's the moral equivalent of the following: public class Foo { private Bar bar; public MethodA() { bar = new Bar(); bar.A(); bar = null; } public MethodB() …
JSBձոգչ
  • 1,310
  • 12
  • 15
65
votes
8 answers

Is ORM an Anti-Pattern?

I had a very stimulating and interessting discussion with a colleague about ORM and its pros and cons. In my opinion, an ORM is useful only in the rarest cases. At least in my experience. But I don't want to list my own arguments at this time. So I…
derphil
  • 859
  • 1
  • 8
  • 9
1
2 3
15 16