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
7
votes
1 answer

If the constant interface anti-pattern is such a crime, why does Swing do it?

I was making a swing application, and realized I had a handful of classes that needed access to the same set of constants. I couldnt bring myself to declare one the primary holder of them and place them all in there and have the others reference it;…
captainroxors
  • 718
  • 7
  • 18
7
votes
2 answers

Enterprise Architecture Anti-patterns

What are the key anti-patterns to avoid when architecting applications for the enterprise? We are using C# and SQL Server and Silverlight, btw - but I imagine some of the anti-patterns will be language neutral.
Craig Schwarze
  • 11,367
  • 15
  • 60
  • 80
7
votes
9 answers

Is Java object containing null variables an anti-pattern? If so which one?

If I query for an object say for an Animal and the returned object is not null but contains null variables is that wrong? For instance I can call animal.getDeathDate(); and since it's not dead yet it returns null. For a Turtle getFlightSpeed() would…
FooBar
  • 1,663
  • 2
  • 12
  • 19
7
votes
1 answer

Using Ninject and binding a default implementation while avoiding the dreaded Service Locator anti-pattern

Is it possible and/or a good idea to use Ninject (or any other IoC container, for that matter) to create a default binding for situations in which an appropriate implementation does not exist, and use this default binding rather than have to handle…
7
votes
1 answer

C++ Help on refactoring a monster class

I have a C background and am a newb on C++. I have a basic design question. I have a class (I'll call it "chef" b/c the problem I have seems very analogous to this, both in terms of complexity and issues) that basically works like this class…
user1790399
  • 220
  • 2
  • 11
7
votes
3 answers

DI Control-Freak anti-pattern: Having trouble understanding

I'm reading Dependency Injection in .NET by Mark Seemann and I can not for the life of me get my head wrapped around this: Although the new keyword is a code smell when it comes to VOLATILE DEPENDENCIES, you don't need to worry about using it for…
Grixxly
  • 464
  • 1
  • 4
  • 17
6
votes
2 answers

Is an instance wrapper around a static class for the purpose of DI an anti pattern?

I have built a little static object for saving generic types to Isolated Storage on WP7. This works grand for older projects but some of the new projects use DI to manage configuration. I am a fan of DI as it means I can change the configuration in…
deanvmc
  • 5,957
  • 6
  • 38
  • 68
6
votes
5 answers

Why is 'smoke and mirrors' an anti-pattern?

I was recently reading Wikpedia's list of Anti-Patterns and noticed that this was included: Smoke and mirrors: Demonstrating how unimplemented functions will appear Why is this a bad thing to do? The only thing I can see is that if you never…
Earlz
  • 62,085
  • 98
  • 303
  • 499
6
votes
1 answer

Are default methods in java interfaces an anti-pattern?

Java 8 introduced default methods on interfaces to provide backwards compatibility for implementations of the collections interfaces, to avoid MethodNotFound errors on legacy libraries. i.e A library with a java 7 implementation of List will not…
murungu
  • 2,090
  • 4
  • 21
  • 45
6
votes
2 answers

Is the actor model not an anti-pattern, as the fire-and-forget style forces actors to remember a state?

When learning Scala, one of the first things I learned was that every function returns something. There is no "void"-function/method as there is, for instance in Java. Thus many Scala-functions are true functions, in a mathematic way, and objects…
Felix Gehring
  • 312
  • 1
  • 9
6
votes
2 answers

Why are Callbacks from Promise `.then` Methods an Anti-Pattern

I have seen answers on StackOverflow where people suggest furnishing a callback function to an AngularJS service. app.controller('tokenCtrl', function($scope, tokenService) { tokenService.getTokens(function callbackFn(tokens) { …
georgeawg
  • 48,608
  • 13
  • 72
  • 95
6
votes
1 answer

Both const and non-const version of the same function - an anti-pattern?

Recently I've inspected a huge amount of legacy C++ code and found something I've never seen before in production C++ code: class Foo { public: void Bar() { std::cout << "Hello from Bar()!" << std::endl; } void Bar() const …
RX_DID_RX
  • 4,113
  • 4
  • 17
  • 27
6
votes
3 answers

Sequential coupling in code

Is sequential coupling really a bad thing in code? Although it's an anti-pattern, the only risk I see is calling methods in the wrong order but documentation of an API/class library with this anti-pattern should take care of that. What other…
GurdeepS
  • 65,107
  • 109
  • 251
  • 387
6
votes
2 answers

Which value is of higher precedence, updatePeriodMillis or the value associated with the Alarm?

I understand that the parameter updatePeriodMillis determines how often an app widget gets updated according to the specification in the widgetproviderinfo.xml present in /res/xml
user3575020
  • 137
  • 1
  • 7
6
votes
2 answers

What type should Struts ActionForm properties be?

I inherited this gigantic legacy Java web app using Struts 1.2.4. I have a specific question regarding ActionForms. Some of them have only String properties (even for numbers), some of them use the seemingly appropriate types (Integer, Date, String,…
thvo
  • 1,532
  • 2
  • 15
  • 29