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
11
votes
2 answers

Why is "call super" considered an anti-pattern according to Wikipedia?

Wikipedia classifies "call super" as an anti-pattern, and I don't really understand why. The pattern is used pretty frequently in objective-C/cocoa; for example init/dealloc, drawrect, awakefromnib all require you to call super. Am I…
eyebrowsoffire
  • 957
  • 7
  • 15
10
votes
3 answers

PHP string constants overuse?

I have two particular cases where I disagree with a coworker, whether constants should be used or not. We use a homemade framework working roughly like Symfony 1.x. Initial code was, in a routing PHP config file for routing, like this…
Maxime Pacary
  • 22,336
  • 11
  • 85
  • 113
10
votes
6 answers

Is there ever justification for the "pseudo-typedef antipattern"?

I have a relatively complicated generic type (say Map>) which I use internally in a class. (There is no external visibility; it's just an implementation detail.) I would like to hide this in a typedef, but Java has no such…
Simon Nickerson
  • 42,159
  • 20
  • 102
  • 127
10
votes
10 answers

Is INTERPRETER an anti-pattern?

To me, the Interpreter patten sounds very much like an anti-pattern known as Greenspun's tenth rule: Any sufficiently complicated C or Fortran program contains an ad hoc, informally-specified, bug-ridden, slow implementation of half of Common…
9
votes
5 answers

Secret Handshake Anti-Pattern

I've just come across a pattern I've seen before, and wanted to get opinions on it. The code in question involves an interface like this: public interface MyCrazyAnalyzer { public void setOptions(AnalyzerOptions options); public void…
Kevin Peterson
  • 7,189
  • 5
  • 36
  • 43
9
votes
5 answers

Alternative to 'for i in xrange(len(x))'

So I see in another post the following "bad" snippet, but the only alternatives I have seen involve patching Python. for i in xrange(len(something)): workwith = something[i] # do things with workwith... What do I do to avoid this "antipattern"?
Alam
9
votes
7 answers

Are set-only properties bad practice?

I have some C# code that loves to create properties that have setters but no getters. To me this seems like an anti-pattern, but am I missing something? public List DataSource { set { // crazy logic here } }
kelloti
  • 8,705
  • 5
  • 46
  • 82
9
votes
3 answers

"Master" associative table?

Consider a model for matching clients and sevices. Clients may be both providers of and consumers of services at various times. Clients may be individuals or groups (companies), the latter having multiple contacts. Contacts may have multiple…
9
votes
1 answer

what is the difference between bloated class and tagged class?

As i read in Effective java Bloated class hierarchies can lead to bloated classes containing many methods that differ only in the type of their arguments, as there are no types in the class hierarchy to capture common behaviors. and in…
Prashant
  • 2,556
  • 2
  • 20
  • 26
9
votes
6 answers

Is a check like isInUnitTest() an antipattern?

I'm working on a personal project (meaning clean source code, no legacy dependencies) and attempting to follow best practices regarding unit testing, dependency management, etc. My company's codebase is littered with code like this: public Response…
dimo414
  • 47,227
  • 18
  • 148
  • 244
9
votes
3 answers

Why is it "wrong to require rubygems"?

According to this post, requiring rubygems is an antipattern. require 'rubygems' The argument seems to boil down to this: When I use your library, deploy your app, or run your tests I may not want to use rubygems. When you require 'rubygems'…
uzo
  • 2,821
  • 2
  • 25
  • 26
9
votes
11 answers

Is it in an anti-pattern to always use get and set methods to access a class's own member fields?

In Java classes is it considered good or bad practice to access member fields with their getters and setters? e.g which is better: public Order { private Agreement agreement; public Agreement getAgreement() { return agreement; } …
Pablojim
  • 8,542
  • 8
  • 45
  • 69
8
votes
5 answers

Do these database design styles (or anti-pattern) have names?

Consider a database with tables Products and Employees. There is a new requirement to model current product managers, being the sole employee responsible for a product, noting that some products are simple or mature enough to require no product…
onedaywhen
  • 55,269
  • 12
  • 100
  • 138
8
votes
5 answers

Can a C# property accept multiple values?

This might be a bit of an anti-pattern, but it is possible for a property on a C# class to accept multiple values? For example, say I have an Public int property and I always want it to return an int, but I would like to be able to have the property…
lomaxx
  • 113,627
  • 57
  • 144
  • 179
8
votes
6 answers

Are try/catch for every single statement that throws an exception considered an anti-pattern?

I am currently reviewing a colleagues Java code, and I see a lot of cases where every single statement that may throw an exception being encapsulated in its own try/catch. Where the catch block all perform the same operation (which operation is not…
Bjarke Freund-Hansen
  • 28,728
  • 25
  • 92
  • 135