Questions tagged [anti-patterns]

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

1
vote
1answer
347 views

How can I get rid of this antipattern

I have a main window and I amgetting data from http client service while form load. public class MainWindow: Window { private IClientService service; public MainWindow(IClientService ...
4
votes
3answers
368 views

Pattern for endpoint that routes requests?

I am building a service that will push notifications to many other services. It has a couple of different notification types that each consumer may care about, but likely will not care about all of ...
20
votes
6answers
2k 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, ...
28
votes
8answers
9k 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 ...
2
votes
2answers
193 views

What is wrong with writing web applications in a way that merges repository layer with view and with controller in the same file?

is there anything wrong with writing code in a way that merges view, repository, controller in the same file? i.e. global $db; // or $db = DBSingleton::get_db_instance(); // or global $container; $...
15
votes
2answers
2k views

Taming the 'utility functions' classes

In our Java codebase I keep seeing the following pattern: /** This is a stateless utility class that groups useful foo-related operations, often with side effects. */ public class FooUtil { ...
0
votes
1answer
124 views

Is a Factory calling a Factory an anti-pattern or an extension of the Single Responsibility Principle?

I'm busy playing around with some training material to help teach some of the juniors the factory pattern. Whilst writing the example, I can't help but think this might be an anti-pattern. Lets say ...
10
votes
7answers
2k views

Violation of the DRY Principle

I am sure there's a name for this anti-pattern somewhere; however I am not familiar enough with the anti-pattern literature to know it. Consider the following scenario: or0 is a member function in a ...
3
votes
4answers
284 views

Is a constant name related to its current value an anti-pattern? [closed]

For example, suppose I have a string constant like this: const TITLEBAR_MESSAGE="Welcome back, %USERNAME%!"; I think it is more readable when it is named as const WELCOME_BACK_USERNAME="Welcome ...
2
votes
2answers
75 views

Swappable state object or decoupling data and functions

I come from OOP pradigm and I also know a bit about functional programming and its advantages. Over time I came to like the separation of data and transformations that are applied to it using pure ...
0
votes
1answer
112 views

How to bring a code to conformance with tell, don't ask without creating tons of methods on other classes?

It used to be fairly common for people to call a getter, do some calculation on it, then call a setter with the result. This is a clear sign your calculation actually belongs to the class you called ...
1
vote
2answers
305 views

What is this anti-pattern's name? (Specialization added directly to a general purpose utility component)

I'll describe the anti-pattern I see occasionally as this. Rather than using encapsulation or inheritance, a utility library grows with feature specializations directly added to it. Subsequent usage ...
24
votes
8answers
3k views

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

This is one of the rules that are beaing 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 ...
2
votes
3answers
1k views

What is this (anti?)pattern called? (or how to describe it)

The case where a source-level operator actually describes an operation to take place at some future point, thunking the real operator together with its operands. I don't know if this has any kind of ...
1
vote
3answers
238 views

How can I resolve this **kwargs antipattern?

I am a hobbyist programmer, working on a much more complex Python project than I've attempted before, which is in the form of a Python library. I find that I'm often passing **kwargs around (as ...
1
vote
2answers
152 views

Is passing an ErrorMessage to be populated inside the receiving method an anti-pattern?

I come from a Java background, and my colleague is from .NET. We are working on a Java project and I saw him create a method like this: public Object myMethod(Object[] param1, ErrorMessage ...
161
votes
7answers
28k 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'...
4
votes
2answers
240 views

Injecting a dependency that is a tree of dependencies

Is it a pattern or antipattern to inject a dependency that is a tree of dependencies? For example: public class ClassExample { private IContainer _container; public ClassExample(IContainer ...
2
votes
1answer
160 views

Is it efficient and a normal practice to have one class with thousands of lines of code? [duplicate]

I am currently in a continuous software product development project on base of legacy Java code. The source code is very complicated, which is good and bad. But I am surprised to see that in the core ...
3
votes
2answers
132 views

Using injection for services that contain only pure functions

Imagine we have a service like the this: class SomeService { // A random pure function that transforms the input // without doing any remote calls or any side effects function ...
2
votes
3answers
361 views

Passing a context object to the constructor or to the method

I am writing a recursive descent parser. Let ParseContext specifies the context for parsing. Pseudocode: class ParseContext { Logger logger; // logger for error/warning messages Locale ...
6
votes
6answers
623 views

Is duplicating files to avoid programming branching a good or anti pattern?

for example, suppose I need to play different sounds according to "grade": file list: fairSound.mp3 goodSound.mp3 excellentSound.mp3 code: showResult(grade){ if(grade==0 || grade==1){ ...
0
votes
0answers
64 views

For a responsive app, do frequent conditionals checking device size indicate a code smell or antipattern?

I have joined a team working on a large and mature responsive website (using a javascript MVC framework), and one thing I frequently see in the codebase is branching code in controllers or components ...
3
votes
3answers
924 views

CQRS+Event Sourcing as Top Level Architecture: Anti-Pattern

I have been study DDD along with CQRS and Event Sourcing. I recently listened to a talk Greg Young gave a couple years ago where he said that CQRS and Event Sourcing are not a top level architecture ...
15
votes
1answer
3k 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 ...
1
vote
3answers
233 views

Perplexed by dependency injection principle - what if it is runtime dependant which objects are created?

The antipattern-plagued game I'm creating is using ASP.NET Core, which, in many cases, requires the use of dependency injection. This is new and counter-intuitive to me. Up to now, I managed to limit ...
1
vote
1answer
108 views

Lookup pattern as a way of passing global references

I am looking at some legacy code in java that uses the Service Locator pattern as a way of passing global references as opposed to passing them over and over again through method arguments and I am ...
0
votes
2answers
1k views

How to avoid using service location when using dependency injection? [closed]

I am trying to use dependency injection in a WPF application, and I really can't figure how to avoid using service location, which is considered to be an anti-pattern in many articles. I am using the ...
0
votes
1answer
921 views

Is this a good service locator, and is this service locator pattern(?) OK?

I'm working in Zend framework 1 and was using Zend_Registry to store objects so that I could replace them in my controllers while unit testing: $auth = Zend_Registry::get('Auth'); // set in Bootstrap....
5
votes
3answers
2k views

God Files versus Ravioli Code

Recently I asked a question about whether or not I should refactor my code. the responses I received were most definitely in the camp of going through with the refactoring due to the presence of a God ...
3
votes
1answer
74 views

Auto-Initializable Objects Pattern

I'm working on a system where we consistently apply "patterns" or approaches such as Dependency Injection. I'd rather not expose the current underlying technology as not to get biased solutions, ...
117
votes
27answers
24k 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, ...
17
votes
5answers
3k 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 ...
14
votes
12answers
3k views

Is this use of conditionals an anti-pattern?

I've seen this a lot in our legacy system at work - functions that go something like this: bool todo = false; if(cond1) { ... // lots of code here if(cond2) todo = true; ... // some other ...
61
votes
5answers
35k 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 ...
-4
votes
5answers
595 views

Why do programmers like to stick to “Thou shalt” / “Thou shalt not” rules that define whether a code is of good or bad quality? [closed]

I'm not sure how to correctly describe my problem... Ever since I started learning how to program, I recognized that many more experienced programmers have very strict (and, in the POV of a beginner, ...
7
votes
2answers
3k views

is switch(this) antipattern or bad practice in Java for Enums?

At work I bumped into a problem to see how enums are growing and storing business logics. As they grew, the constructors grew a lot. At one point I found out instead of putting in let's say the tenth ...
-1
votes
1answer
250 views

Refactoring bad code switch statment without distort everything

Once in a while I’m stumbling on switch statements during a Code Review session. I would like to find a more elegant way of this code .... $istannceOfClass = $repository->loadFoo(); switch($...
8
votes
3answers
907 views

For-if antipattern

I was reading on this blog post about the for-if anti-pattern, and I'm not quite sure I understand why it's an anti-pattern. foreach (string filename in Directory.GetFiles(".")) { if (filename....
4
votes
2answers
6k views

Is it antipattern to use React.cloneElement to extend an element?

I'm creating a popover component for a UI in React. That component contains a button that triggers the popover to display. Because the button needs to be configurable--label, classes, properties--I ...
3
votes
2answers
417 views

What differentiates function objects from poltergeists?

The Short (Original) Version How are function objects, sometimes called "functors" in C++ and other OO languages, where they make sense different from classes symptomatic of the poltergeist anti-...
0
votes
1answer
71 views

Is creating near duplicate partial views solely for populating html elements with Ajax returns violating DRY?

Maybe anti-pattern is a better word for this question. I do not know, but I mean a violation of DRY. Id like to reuse a partial view, and I can, but that partial view has other things in it I don't ...
3
votes
6answers
2k views

Best approach - convert multiple conditional if -else in a more handy design

I have a class that handles the state of a response, called StockResponse. The code has multiple ifs to handle each state of the stock. Most of the cases has a default behaviour, but some conditions ...
2
votes
6answers
630 views

design pattern for conditional behaviour depending on a client ID

I don't know if there actually is one design pattern, or several together, or maybe what i'm asking is anti-pattern. Context (simplified) : my company sells SaaS services (through an API) to several ...
124
votes
9answers
59k 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 ...
-6
votes
3answers
891 views

How can hard-coding be considered a code smell in the age of micro-services?

As an intermediate stage hard-coding is accepted by Google in their Tour of Heroes Angular tutorial but the benefit cannot surely only be for novices. Do people not understand that hard-coding as an ...
1
vote
1answer
654 views

Using inner classes to achieve thread-safe behavior without synchronization

I have some classes that contains both immutable (primitive & references) and mutable data, but mutability come from external writes (another process). To avoid using synchronized on every ...
28
votes
2answers
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. ...
1
vote
1answer
353 views

Does this anti-pattern have a name?

Here is a piece of cool code to add the two integers, a and b: NameService nameService = NameService.getSingletonInstance(); OperationService operationService = nameService.resolve(OperationService....
38
votes
9answers
23k 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 ...