Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [anti-patterns]

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

27
votes
8answers
8k 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 ...
3
votes
2answers
177 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; $...
0
votes
1answer
120 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 ...
3
votes
4answers
280 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
67 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
111 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
304 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 ...
0
votes
1answer
255 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 service)...
1
vote
3answers
208 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 ...
4
votes
2answers
237 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
159 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
131 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 ...
6
votes
6answers
621 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 ...
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 ...
1
vote
3answers
206 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 ...
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, ...
3
votes
1answer
72 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, ...
2
votes
3answers
315 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 ...
16
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 ...
3
votes
3answers
886 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 ...
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 ...
-4
votes
5answers
585 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, ...
0
votes
1answer
231 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
851 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....
3
votes
2answers
410 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
65 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 ...
-6
votes
3answers
855 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
628 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 ...
2
votes
2answers
5k 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 ...
2
votes
6answers
593 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 ...
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 ...
158
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'...
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....
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, ...
3
votes
4answers
307 views

Is there a valid reason to separate expectations from tests?

I've inherited an application that has a suite of tests that drive me batty. But one of the design decisions that this test suite takes that completely leaves me scratching my head is the separation ...
1
vote
2answers
645 views

Is a god class still bad practice if it is used with mixins?

Every description I have read about god classes considers them to be an anti-pattern and a bad practice. Most descriptions I have read about mixins considers them to be acceptable in some cases. If ...
1
vote
1answer
373 views

Refactoring god-class leads to feature envy [closed]

I'm trying to refactor a 2.5KLOC god-class (with about 68 data members and 62 member functions) that performs a wide variety of text formatting and layout operations. After a careful analysis based on:...
8
votes
3answers
3k views

DDD - Is anemic domain model an antipattern? Shoud we be using rich domain models? [closed]

Anemic domain model was criticized a long time ago by Evans and Fowler, since apparently it goes against object oriented principles, etc. The DDD community is clearly aligned with this statements. ...
2
votes
2answers
232 views

Is an imposed workflow of services call an antipattern?

We have an application using a bunch of services. As soon as the application is launched it should call a webservice method, "RegisterMachineSession". In this method we accomplish some basic work that ...
2
votes
3answers
744 views

How to manage configuration and state in a program

At my company we have multiple C# programs that use Dictionaries in a config class to keep track of the configuration and state of the program. For example, bool isFoo = config.GetBool("Foo"); ...
54
votes
8answers
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. ...
3
votes
2answers
553 views

How to use Dependency-injection Containers correctly when they hide dependencies from outer classes?

From Zend Docs there is this example of how to use Zend\Di, which is a dependency injection container of Zend Framework: // inside a bootstrap somewhere $di = new Zend\Di\Di(); // inside each ...
-3
votes
3answers
326 views

how to protect against theft of a class. (neural network class) [duplicate]

I am writing software that makes use of a neural net. What makes my network special as compared to others, is the way I train them. Its non standard, its something that I don't want to give away to ...
0
votes
4answers
368 views

How to deal with low or medium dev team level?

In our team we have some low / medium level developers: they know how to write C#/JavaScript code, but most of it is an anemic domain model in a purely functionnal way of coding, but there are no unit ...
-3
votes
2answers
1k views

What is the difference between Code Smells and Anti Patterns?

I am trying to understand the difference between these two terms. In some contexts that these two terms have been used interchangeably. What is the exact difference between these two terms ?
5
votes
4answers
3k views

Multiple properties/methods giving the same result

I'm trying to ascertain whether the use of multiple references to the same property is code smell / an anti-pattern, based on the needs of the organisation. As an example, consider: abstract class ...
3
votes
3answers
375 views

Representing a status as single letter strings [duplicate]

I worry that I'm too concerned with code smells. I've spent the last two days procrastinating over implementation details and how I would actively refuse using the approach suggested. We have a ...
17
votes
2answers
2k views

What is the For-Case Antipattern?

Today's TDWTF article starts with a confession from the author: I didn’t know what the For-Case anti-pattern was until relatively recently, when there were a spate of articles condemning it as an ...
101
votes
11answers
9k 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 ...