Questions tagged [anti-patterns]
An anti-pattern is a behavior or practice that is common despite being ineffective or counterproductive.
238
questions
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, ...
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 ...
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'...
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 ...
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
...
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 ...
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 ...
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 ...
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 ...
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 ...
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();...
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 ...
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 ...
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 ...
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 ...
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. ...
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 ...
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 ...
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 ...
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 ...
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 {
...
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 ...
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 ...
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
{
...
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 ...
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, ...
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: ...
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 ...
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 ...
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'...
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(...
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 ...
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 ...
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 ...
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 ...
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 ...
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.
...
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 ...
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 ...
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 ...
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(...
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 ...
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 ...
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 ...
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 ...