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

Is it considered bad practice or an anti-pattern to wrap a linked list in another structure that only contains the head of the list?

For example, using C, let's say I define a node like this: typedef struct nde { int val; struct nde* next; }node; And then I "wrap" it with something like this: typedef struct lst { node* head; }list; I do mean this case specifically.…
josepi
  • 31
  • 1
3
votes
0 answers

What makes a ServiceLocator be an anti-pattern?

I am struggling on what makes the ServiceLocator an anti-pattern. Some say, that passing the container around qualifies it as an antipattern, others fear the maintainability once the app grows (hidden dependencies). The following sample demonstrates…
Trinitrotoluol
  • 205
  • 1
  • 13
3
votes
6 answers

How to see "anti if" movement and its goal?

I have a developer for last 3 years, have been using if-else or if-else if statements a lot in my programing habit. And today, I found This link. One obvious sample i put here public void doSomthing(String target, String object){ //validate…
3
votes
1 answer

logging exception and throwing new exception - is it antipattern?

If we catch exception and then we throw exception, but not the same type (just based on first one) is it still antipattern to log first one? Simple example: } catch (CloneNotSupportedException e) { log.warn(e, e.getMessage()); throw…
uncleMatuesz
  • 87
  • 1
  • 1
  • 10
3
votes
0 answers

Is having a public getLock() or getMutex() function an antipattern?

I once had the pleasure of trying to identify possible concurrency issues in a C++ codebase where I kept seeing a pattern something like this: lock(obj.getLock()); obj.foo(); unlock(obj.getLock()); or worse: public void bar(SomeObject obj) { …
3
votes
1 answer

Difference between "foo.bar" and "foo['bar']" in js

I have to make sense of a codebase I was given on my new job. I can see many anti-patterns here, one of them is a "god object", which contains a lot of things and different object access it all the time. That's a different problem, my question here…
shal
  • 2,854
  • 4
  • 20
  • 31
3
votes
3 answers

What coding or design patterns can I use to enforce a required sequence of method calls?

I wrote the following lines of code: $this->validate($group); $this->em->persist($group); $this->em->flush(); Method "validate" will throw an exception if $group is not valid. The issue is, it seems kind of "fragile". If another developer changed…
Lukas Lukac
  • 7,766
  • 10
  • 65
  • 75
3
votes
1 answer

If getOrCreate is an antipattern, how can I avoid it?

According to http://martinfowler.com/bliki/CQRS.html I believe getOrCreate function is an antipattern. function getOrCreateObj(something) { let f = find(something, db); if (f) return f; else return createObj(something); } What should I do…
Novellizator
  • 13,633
  • 9
  • 43
  • 65
3
votes
2 answers

In JavaScript, is it a good practice to depend on object references to "listen" for changes?

I have to implement a repository pattern-like object that will maintain a list of items. The repo would look something like this: var repository = { data: [], getAll: function() { return this.data; }, update: function() {…
3
votes
4 answers

lisp: dynamic scope vs explicit parameter passing

I see two different patterns for "output" functions in (common) lisp: (defun implicit () (format t "Life? Don't talk to me about life!")) (defun explicit (stream) (format stream "This will all end in tears.")) (defun test-im-vs-ex-plicit () …
3
votes
5 answers

Book for Anti Design Patterns

I have heard a lot about anti patterns and would like to read a book on this,which book would you suggest for Anti patterns.
Pranali Desai
  • 974
  • 1
  • 7
  • 22
3
votes
1 answer

Scaling singletons

After having some difficult hours mulling over some architecture issues for my server-based application, I feel I am going to have to use singletons to accomplish my goal. Purely for the following reasons (justifying my smell): I don't need to pass…
Program.X
  • 7,250
  • 12
  • 49
  • 83
3
votes
1 answer

Can I use Ninject to inject dependencies into attributes rather than using the service locator pattern?

I'm using feature flags to selectively enable/disable certain aspects of my MVC4 web application in different environments. I have an interface named IConfiguration with a IsEnabled(FeatureFlag) method that provides access to these flags. To this…
Brant Bobby
  • 14,956
  • 14
  • 78
  • 115
3
votes
4 answers

Take 2: Is it abusive to use IDisposable and “using” as a means for getting “scoped behavior”?

TL;DR -- Is it ever appropriate to execute business logic in IDisposable.Dispose? In my search for an answer, I read through the question: Is it abusive to use IDisposable and "using" as a means for getting "scoped behavior" for exception safety? It…
Charles Josephs
  • 1,495
  • 3
  • 14
  • 25
3
votes
4 answers

Reducing the complexity of the code

I'm stuck right now with some really weird classes, that have the logic mixed up. Here is the example of the code that generates a query to the database: if(realTraffic.getPvkp() != null) { //Admission point …
SPIRiT_1984
  • 2,717
  • 3
  • 29
  • 46