Skip to main content

Questions tagged [anti-patterns]

An anti-pattern is a behavior or practice that is common despite being ineffective or counterproductive.

Filter by
Sorted by
Tagged with
618 votes
13 answers
272k views

So Singletons are bad, then what?

There has been a lot of discussion lately about the problems with using (and overusing) Singletons. I've been one of those people earlier in my career too. I can see what the problem is now, and yet, ...
Bobby Tables's user avatar
  • 20.6k
242 votes
10 answers
36k views

Is there a name for the (anti- ) pattern of passing parameters that will only be used several levels deep in the call chain?

I was trying to find alternatives to the use of global variable in some legacy code. But this question is not about the technical alternatives, I'm mainly concerned about the terminology. The ...
RubenLaguna's user avatar
  • 1,932
236 votes
7 answers
93k views

What is wrong with magic strings?

As an experienced software developer, I have learned to avoid magic strings. My problem is that it is such a long time since I have used them, I've forgotten most of the reasons why. As a result, I'...
Kramii's user avatar
  • 14.1k
212 votes
11 answers
146k views

Are exceptions as control flow considered a serious antipattern? If so, Why?

Back in the late 90's I worked quite a bit with a code base that used exceptions as flow control. It implemented a finite state machine to drive telephony applications. Lately I am reminded of those ...
Aaron Anodide's user avatar
161 votes
13 answers
235k views

Is using nested try-catch blocks an anti-pattern?

Is this an antipattern? It is an acceptable practice? try { //do something } catch (Exception e) { try { //do something in the same line, but being less ambitious ...
Mister Smith's user avatar
  • 2,977
137 votes
27 answers
32k views

Is source code generation an anti-pattern?

If something can be generated, then that thing is data, not code. Given that, isn't this whole idea of source code generation a misunderstanding? That is, if there is a code generator for something, ...
115 votes
17 answers
24k views

Why should 'boneheaded' exceptions not be caught, especially in server code?

I am confused because in quite a few places I've already read that the so-called 'boneheaded' exceptions (ones that result from bugs in code) are not supposed to be caught. Instead, they must be ...
gaazkam's user avatar
  • 4,499
105 votes
11 answers
10k views

What's the name of the antipattern opposite to "reinventing the wheel"? [closed]

The "Reinvent the wheel" antipattern is a pretty common one - instead of using a ready solution, write your own from scratch. Code base grows needlessly, slightly different interfaces that do the same ...
SF.'s user avatar
  • 5,176
104 votes
9 answers
24k views

Is putting general-use functions in a "helpers" file an anti-pattern or code smell?

Is it an anti-pattern or code smell to put "general use" functions (examples below) into a catch-all file named "helpers" or "utils"? It's a pattern I've seen quite a lot ...
old greg's user avatar
  • 939
101 votes
60 answers
12k views

Which things instantly ring alarm bells when looking at code? [closed]

I attended a software craftsmanship event a couple of weeks ago and one of the comments made was "I'm sure we all recognize bad code when we see it" and everyone nodded sagely without further ...
99 votes
34 answers
66k views

"Comments are a code smell" [closed]

A coworker of mine believes that any use of in-code comments (ie, not javadoc style method or class comments) is a code smell. What do you think?
87 votes
7 answers
66k views

EAV - is it really bad in all scenarios?

I'm thinking to use an entity-attribute-value (EAV) model for some of the stuff in one of the projects, but all questions about it in Stack Overflow end up to answers calling EAV an anti-pattern. But ...
Giedrius's user avatar
  • 1,304
84 votes
8 answers
72k views

Is modifying an incoming parameter an antipattern? [closed]

I am programming in Java, and I always make converters sort of like this: public OtherObject MyObject2OtherObject(MyObject mo){ ... Do the conversion return otherObject; } At the new ...
CsBalazsHungary's user avatar
71 votes
14 answers
6k views

Name for this antipattern? Fields as local variables [closed]

In some code I'm reviewing, I'm seeing stuff that's the moral equivalent of the following: public class Foo { private Bar bar; public MethodA() { bar = new Bar(); bar.A();...
JSBձոգչ's user avatar
  • 1,440
65 votes
8 answers
29k views

Is ORM an Anti-Pattern? [closed]

I had a very stimulating and interessting discussion with a colleague about ORM and its pros and cons. In my opinion, an ORM is useful only in the rarest cases. At least in my experience. But I don't ...
derphil's user avatar
  • 859
61 votes
12 answers
54k views

Are utility classes with nothing but static members an anti-pattern in C++?

The question Where should I put functions that are not related to a class has sparked some debate over whether it makes sense in C++ to combine utility functions in a class or just have them exist as ...
PersonalNexus's user avatar
58 votes
3 answers
42k views

Is it an antipattern to use peek() to modify a stream element?

Suppose I have a stream of Things and I want to "enrich" them mid stream, I can use peek() to do this, eg: streamOfThings.peek(this::thingMutator).forEach(this::someConsumer); Assume that ...
Bohemian's user avatar
  • 2,016
57 votes
5 answers
5k views

Is jQuery an example of "god object" antipattern?

I want to ask – I am slowly learning jQuery. What I see is an exact example of a God Object anti-pattern. Basically, everything goes to the $ function, whatever it is. Am I right and is jQuery ...
Karel Bílek's user avatar
54 votes
8 answers
8k views

Term (or "pattern"?) for "Do something if it's not already done" [closed]

Sounds pretty basic, I know, but I recently had a colleague tell me that a method called startHttpServer is too complicated to understand because it only starts the server if it's not already running. ...
John Calcote's user avatar
53 votes
19 answers
10k views

Forcing people to read and understand code instead of using comments, function summaries and debuggers? [duplicate]

I am a young programmer (finished computer science university but still under a year of working in the industry) and I recently got a job working on some C code for a decent size web service. Looking ...
48 votes
6 answers
17k views

Good or bad practice to mask Java collections with meaningful class names?

Lately I've been in the habit of "masking" Java collections with human-friendly class names. Some simple examples: // Facade class that makes code more readable and understandable. public class ...
herpylderp's user avatar
  • 2,057
47 votes
11 answers
11k views

Are error variables an anti-pattern or good design?

In order to handle several possible errors that shouldn't halt execution, I have an error variable that clients can check and use to throw exceptions. Is this an Anti-Pattern? Is there a better way to ...
Mikayla Maki's user avatar
46 votes
8 answers
4k views

Code maintenance: keeping a bad pattern when extending new code for being consistent, or not?

I have to extend an existing module of a project. I don't like the way it has been done (lots of anti-pattern involved, like copy/pasted code). I don't want to perform a complete refactor for many ...
Guillaume's user avatar
  • 2,197
44 votes
11 answers
6k views

Are so called "cross-cutting concerns" a valid excuse to break SOLID/DI/IoC?

My colleagues like to say "logging/caching/etc. is a cross-cutting concern" and then proceed using the corresponding singleton everywhere. Yet they love IoC and DI. Is it really a valid excuse to ...
Den's user avatar
  • 4,847
44 votes
13 answers
9k views

Is it an (anti-)pattern for a function to have an argument to decide which other function to call?

Consider your have an enumeration that looks like this: enum ProcessingType { CONFABULATION, RETICULATION, SPLICING; } And you have a web-service that looks like this: class WebService { ...
Mathieu's user avatar
  • 1,039
40 votes
5 answers
5k views

Is it considered an anti-pattern to read from STDIN from within a library?

While writing a library for a large project I'm working on at work, an issue came up which required a token to be sent to an email address, and then passed back into the code where it can then be used ...
Paradoxis's user avatar
  • 1,361
38 votes
15 answers
10k views

If nulls are evil, what should be used when a value can be meaningfully absent?

This is one of the rules that are being repeated over and over and that perplex me. Nulls are evil and should be avoided whenever possible. But, but - from my naivety, let me scream - sometimes a ...
gaazkam's user avatar
  • 4,499
37 votes
9 answers
10k views

Is creating subclasses for specific instances a bad practice?

Consider the following design public class Person { public virtual string Name { get; } public Person (string name) { this.Name = name; } } public class Karl : Person { ...
Ignacio Soler Garcia's user avatar
37 votes
11 answers
7k views

Constructor-only subclasses: Is this an anti-pattern?

I was having a discussion with a co-worker, and we ended up having conflicting intuitions about the purpose of subclassing. My intuition is that if a primary function of a subclass is to express a ...
HardlyKnowEm's user avatar
36 votes
6 answers
21k views

Why is it wrong to comment out code and then gradually remove it to keep track of what I've already done and what remains to be done?

Whenever I find out that a large portion of my code needs to be changed, either because it is incorrect or because it needs to be adapted to major architectural changes necessited by other reasons, ...
gaazkam's user avatar
  • 4,499
35 votes
6 answers
7k views

Code that converts a value into a different representation, then converts it back to where it started is bad, but how? [closed]

I was reading an article about bad programming practices. It mentioned - "Yo-Yo code" that converts a value into a different representation, then converts it back to where it started (eg: ...
user13107's user avatar
  • 491
35 votes
9 answers
45k views

Is there a better way to use C# dictionaries than TryGetValue?

I find myself often looking up questions online, and many solutions include dictionaries. However, whenever I try to implement them, I get this horrible reek in my code. For example every time I want ...
Adam B's user avatar
  • 1,645
35 votes
10 answers
11k views

What naming anti-patterns exist? [closed]

There are some names, where if you find yourself reaching for those names, you know you've already messed something up. For example: XxxManager This is bad because a class should describe what the ...
35 votes
10 answers
33k views

Alternatives to the singleton pattern

I have read different opinions about the singleton pattern. Some maintain that it should be avoided at all costs and others that it can be be useful in certain situations. One situation in which I ...
Giorgio's user avatar
  • 19.7k
34 votes
8 answers
14k views

Is throwing an exception an anti-pattern here?

I just had a discussion over a design choice after a code review. I wonder what your opinions are. There's this Preferences class, which is a bucket for key-value pairs. Null values are legal (that'...
Konrad Morawski's user avatar
33 votes
3 answers
11k views

How to tackle a 'branched' arrow head anti-pattern? [duplicate]

I recently read this question that features, the arrow anti-pattern. I have something similar in code I'm trying to refactor except that it branches. It looks a little something like this: if(...
AncientSwordRage's user avatar
30 votes
12 answers
22k views

What design patterns are the worst or most narrowly defined? [closed]

For every programming project, managers with past programming experience try to shine when they recommend some design patterns for your project. I like design patterns when they make sense or if you ...
Akku's user avatar
  • 457
29 votes
10 answers
10k views

How many are too many interfaces on a class? [closed]

I would probably consider it a code smell or even an anti-pattern to have a class that implements 23 interfaces. If it is indeed an anti-pattern, what would you call it? Or is it simply just not ...
Jonas Elfström's user avatar
29 votes
7 answers
10k views

Is my company merging branches wrong?

I recently came across an MSDN article about branching and merging and SCM: Branching and Merging Primer - Chris Birmele. In the article they say 'big bang merge' is a merging antipattern: Big ...
user6567423's user avatar
28 votes
2 answers
3k views

Is there a named anti pattern for historically grown software? [closed]

Is there an anti pattern that describes a historically grown software system where multiple developers just added new features to the system but no one really kept an eye on the overall architecture ...
Jens's user avatar
  • 391
28 votes
8 answers
3k views

What to do about "Failure Driven Development"?

At our shop, we strive to be agile. And I'd say we are making great strides. That said, a few of us have spotted a pattern we have started calling "Failure Driven Development". Failure Driven ...
DevSolo's user avatar
  • 2,814
28 votes
2 answers
3k views

What is the name of the following (anti) pattern? What are its advantages and disadvantages?

Over the last few months, I stumbled a few times over the following technique / pattern. However, I can't seem to find a specific name, nor am I a 100% sure about all its advantages and disadvantages. ...
Jérôme's user avatar
  • 669
27 votes
12 answers
4k views

Is there an antipattern to describe this method of coding? [closed]

I have a codebase where the programmer tended to wrap things up in areas that don't make sense. For example, given an Error log we have you can log via ErrorLog.Log(ex, "friendly message"); He ...
P.Brian.Mackey's user avatar
27 votes
1 answer
20k views

Where did "exit(-1)" come from?

I see in a lot of legacy software and bad tutorials on the Internet that recommend using exit(-1), return -1 or similar to represent "abnormal termination". The problem is, in POSIX at least, -1 has ...
user222973's user avatar
24 votes
5 answers
15k views

Is the use of ***Helper or *** Util classes containing just static methods an AntiPattern

I am often confrontated with helper or util classes in Java or whatever kind of language. So I was asking myself if this is some kind of Anti Pattern and the existence of these kind of classes is ...
Diversity's user avatar
  • 349
22 votes
1 answer
18k views

Is it still an antipattern if we log an exception message and throw a different exception?

Our webapplication is using an ExceptionMapper to map some exceptions to Response. We log the exception messages before throwing a new exception as follows: catch (SomeException ex) { LOG.error(...
Diyarbakir's user avatar
21 votes
7 answers
36k views

Passing an object into a method which changes the object, is it a common (anti-) pattern?

I am reading about common code smells in Martin Fowler's Refactoring book. In that context, I was wondering about a pattern I am seeing in a code base, and wether one could objectively consider it an ...
Michiel van Oosterhout's user avatar
21 votes
1 answer
6k views

What is priming the pump? Sometimes called a priming read

I was taught this expression and pattern way back in the day. Sure, the name comes from old pumps that needed to be filled with water before they could pump water, but who cares? We're talking about ...
candied_orange's user avatar
19 votes
5 answers
5k views

TDD Mock call verification - is it an anti-pattern?

I've been doing TDD for a while now, I feel pretty good about it, I love my test suites and all. However I've noticed that lately I've been doing a lot of mock call verification. For example I'd have ...
Dimitar Dimitrov's user avatar
19 votes
2 answers
7k views

To load or not to load data for unit tests from external files

When unit testing I often find myself debating how much of the data I feed to, and expect back from my units under test, I should include in the actual test files. The tradeoff I constantly ...
DudeOnRock's user avatar
  • 1,079

1
2 3 4 5