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

How does the initialization of classes in Scala work?

The code below throws a java.lang.NullPointerException because the trait is initialized prematurely. trait DummyTrait { def intSeq: Seq[Int] require(intSeq.exists(_ > 2)) } object Dummy extends DummyTrait { val extraIntSeq: Seq[Int] =…
4
votes
2 answers

Is the 'synchronized' keyword in a classic enterprise application suspicious?

I am talking about classic enterprise applications. Typically hosted in some kind of application-server or container. Nothing fancy, just entities, services, Presentation/UI and relational storage. Whenever I see the synchronized keyword (either on…
jbandi
  • 17,499
  • 9
  • 69
  • 81
4
votes
2 answers

C++ COM : Common mistakes

I'm having to immerse myself in C++ COM programming again, and have forgotten most of the hard-learned lessons from last time. (when I think the phrase 'never again' may have been used in error.) What are the most common mistakes and anti-patterns…
Roddy
  • 66,617
  • 42
  • 165
  • 277
4
votes
7 answers

Resolving a call-chain anti-pattern

I've begun to notice something of an anti-pattern in my ASP.NET development. It bothers me because it feels like the right thing to do to maintain good design, but at the same time it smells wrong. The problem is this: we have a multi-layered…
CodexArcanum
  • 3,944
  • 3
  • 35
  • 40
4
votes
1 answer

Difference between the design pattern and anti-pattern

I'm reading the theory about designing software architecture and I see there are some theories such as SOLID principles, Design Pattern and Anti-Pattern that we should consider when we design our software. My Question: What are the differences…
AhmadReza Payan
  • 2,171
  • 1
  • 23
  • 33
4
votes
6 answers

Last Updated Date: Antipattern?

I keep seeing questions floating through that make reference to a column in a database table named something like DateLastUpdated. I don't get it. The only companion field I've ever seen is LastUpdateUserId or such. There's never an indicator about…
dkretz
  • 37,399
  • 13
  • 80
  • 138
4
votes
1 answer

Why is an anti-pattern letting a react component to edit its own props?

I was searching for an answer to another problem and I found this answer (link) I'm just curious why is it that modifying its own props is an anti-pattern, and why isn't it that modifying its own state is not and anti-pattern?
Mike W
  • 1,303
  • 1
  • 21
  • 31
4
votes
2 answers

Is an empty flag a bad habit?

I faced a very stupid bug a few days ago. It was caused by this enum I get from third-party library: [Flags] public enum MyStatus { OKResponse = 0, ResponseTooBig = 1, ErrorMessage = 2, NoResponse = 4, ... } I am used to check…
vojta
  • 5,591
  • 2
  • 24
  • 64
4
votes
1 answer

Is there a name for this anti-pattern (a function with modes)?

Every so often a programmer notices that he has some very similar code in a few places. Lets say here are there instances of similar code. (This is a toy example for clarity. in the wild, this anti-pattern generally doesn't occur on code quite…
zevdg
  • 1,091
  • 2
  • 9
  • 20
4
votes
0 answers

Top misrepresentations in programming?

I often find that design patterns, libraries, and frameworks promise great things and sound awesome - until you actually study them and realize that what they say sounds better than it actually is. Forklift Code…
Xeoncross
  • 55,620
  • 80
  • 262
  • 364
4
votes
4 answers

Risking the exception anti-pattern.. with some modifications

Lets say that I have a library which runs 24x7 on certain machines. Even if the code is rock solid, a hardware fault can sooner or later trigger an exception. I would like to have some sort of failsafe in position for events like this. One approach…
Sridhar Iyer
  • 2,772
  • 1
  • 21
  • 28
4
votes
1 answer

Angular Interdependent Services: Avoiding circular dependncy

I have two separate GUIs that are part of the same system. One at the top of the screen (navEditor) and one on the side (routeEditor). They need two update each other frequently, and call each others functions. Each has service that holds most of…
4
votes
2 answers

JavaScript: creating a reference to 'this' (e.g. 'var _this = this') vs. bind/call/apply

Relying on this in the wrong context is a common pitfall. A contrived example: function SomeClass() { this.prop = 42; document.body.addEventListener('click', function() { alert(this.prop); // will be undefined }); } new…
tobek
  • 4,349
  • 3
  • 32
  • 41
4
votes
3 answers

Is a generic model an antipattern?

Now I have something that I have not seen it before: the database is really generic. For example: instead of a concrete type we have a generic one: device, and it relates to a custom properties table. Unfortunatelly, the model over its entities…
Pablo Castilla
  • 2,723
  • 2
  • 28
  • 33
4
votes
5 answers

Does anybody recognize any pattern/antipattern in attached class diagram?

alt text http://img8.imageshack.us/img8/8558/classdiagram.png Short description: I have a doubt whether it's normal that AbstractCrudDaoImpl implements both interface and abstract class which are inherited from the same parent (ReadOnlyDao).
Roman
  • 64,384
  • 92
  • 238
  • 332