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
8
votes
4 answers

Name of the anti-pattern of keeping old obsolete code around

Recently I took a look at some code I'd committed to our version control system at work, and I found a bunch of it had been replaced (that's OK) but the old version was still there, commented out. I guess the guy felt a bit "insecure" about deleting…
Adrian Smith
  • 17,236
  • 11
  • 71
  • 93
8
votes
3 answers

Abuse of Closures? Violations of various principles? Or ok?

Edit: fixed several syntax and consistency issues to make the code a little more apparent and close to what I actually am doing. I've got some code that looks like this: SomeClass someClass; var finalResult = DoSomething(() => { var result…
Derick Bailey
  • 72,004
  • 22
  • 206
  • 219
8
votes
1 answer

Creating custom events - Object Sender or Typed Sender?

I searched through the archives and I found lots of questions about what sender is and why you should use the pattern but I didn't see anything about a custom event and the type if sender. Say I am creating a custom class called Subscription and it…
Ryan Pedersen
  • 3,177
  • 27
  • 39
8
votes
6 answers

Is this an anti-pattern?

The situation is this: You have two classes that both implement the same interface and both classes work together to complete some business process. For example networkUserManager and localUserManager implement IUserManager which has a method…
insipid
  • 3,238
  • 3
  • 26
  • 38
8
votes
6 answers

Abuse using and Dispose() for scope handling of not to be released objects?

For convenience and safety reasons i'd like to use the using statement for allocation and release of objects from/to a pool public class Resource : IDisposable { public void Dispose() { ResourcePool.ReleaseResource(this); …
FrankU
  • 83
  • 3
8
votes
4 answers

Antipatterns with Ruby on Rails

What are most common Ruby on Rails antipatterns and how to avoid them?
Jakub Arnold
  • 85,596
  • 89
  • 230
  • 327
8
votes
4 answers

Java antipattern name? Objects containing objects containing... etc

Is there a name or a particular rule for objects that contain objects that contain... and so on. I'm working with a complex system that often has objects running 5-10 layers deep. One reason I'm hearing for why this is done is to pass a lot of…
FooBar
  • 1,663
  • 2
  • 12
  • 19
8
votes
6 answers

Why defining properties in the prototype is considered an antipattern

I often see this pattern to define javascript objects function Person(name) { this.name = name; } Person.prototype.describe = function () { return "Person called "+this.name; }; And in this article it says that adding properties directly to…
7
votes
2 answers

Rails Domain model decoupling of Activerecord

I have been reading the book "SQL Antipatterns: Avoiding the Pitfalls of Database Programming" especially around the magic beans anti pattern. In it shows a diagram decoupling activerecords by using a domain model and has example in PHP, but not…
7
votes
3 answers

Dependency Injection - use with Data Transfer Objects (DTOs)?

Consider the code below (which has been simplified). I have a service class that returns a list of specific DTO objects that each implement their own specific interface. In the actual code these are getting populated by iterating thru a Dataset as…
Matt
  • 14,353
  • 5
  • 53
  • 65
7
votes
3 answers

Is grouping multiple @Service and @Repository classes into wrappers an anti-pattern?

Question is a bit rhetorical. I've had an argument with my colleagues regarding the following pattern: @Component public class MetaService { public static UserService userService; public static GroupService groupService; public…
7
votes
5 answers

C#: Enum anti-patterns

There has been talk of Enums in general violating Clean Code-principles, so I'm looking for people's favorite Enum anti-patterns and alternative solutions for these. For example I've seen code like this: switch(enumValue) { case myEnum.Value1: …
Seb Nilsson
  • 26,200
  • 30
  • 103
  • 130
7
votes
18 answers

What types of coding anti-patterns do you always refactor when you cross them?

I just refactored some code that was in a different section of the class I was working on because it was a series of nested conditional operators (?:) that was made a ton clearer by a fairly simple switch statement (C#). When will you touch code…
Jeff Martin
  • 10,812
  • 7
  • 48
  • 74
7
votes
3 answers

Is using D string mixins for code reuse an anti-pattern?

For those of you who are not familiar with D string mixins, they're basically compile-time evals. You can take any compile time string (whether a literal or generated by template metaprogramming or compile time function evaluation) and compile it…
dsimcha
  • 67,514
  • 53
  • 213
  • 334
7
votes
3 answers

Wrappers/law of demeter seems to be an anti-pattern

I've been reading up on this "Law of Demeter" thing, and it (and pure "wrapper" classes in general) seem to generally be anti patterns. Consider an implementation class: class FluidSimulator { void reset() { /* ... */ } } Now consider two…
Robert Fraser
  • 10,649
  • 8
  • 69
  • 93