Stack Exchange Network

Stack Exchange network consists of 174 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.

4
votes
2answers
224 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
135 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 ...
2
votes
2answers
117 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 ...
7
votes
6answers
601 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
63 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
151 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
148 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 ...
18
votes
6answers
1k 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
66 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
170 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 ...
14
votes
5answers
1k 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
661 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 ...
18
votes
7answers
1k 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
458 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
173 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
661 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
376 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
44 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 ...
-5
votes
3answers
626 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
467 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 ...
1
vote
2answers
3k 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
6answers
428 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
859 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 ...
155
votes
7answers
25k 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
336 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....
115
votes
27answers
23k 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
562 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
305 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:...
7
votes
3answers
2k 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
219 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
437 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"); ...
53
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. ...
2
votes
2answers
480 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
299 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
360 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
937 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
2k 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
374 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 ...
2
votes
4answers
1k views

Design pattern for multiples APIs that do the same function

I retrieve some pieces of information from four forecasting APIs, I have three main methods that I will implement in each API's manager: history (only one of them provides this function) ...
39
votes
5answers
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 ...
3
votes
6answers
438 views

Is it an anti-pattern to use the return type of an assignment as part of a condition?

I must set a bool to be passed down from a controller to a view in my MVC solution as well as do something (as part of an if). I thought, in order to keep the code concise, I could kill two birds with ...
3
votes
2answers
295 views

Javascript: using magic object keys

I just wrote a function and I'm not sure if it is a good idea. The motivation is, I'd like to store some internal bookkeeping data along with my business data in one big happy javascript object. ...
6
votes
4answers
1k views

Singleton without any state

I worked on a project and found a working solution, but now I got some questions on how I solved some problems in the code. First of all, I am no expert in design patterns, but I know the (anti-)...
5
votes
6answers
1k views

Command Pattern vs Functional Decomposition

Android developers probably are familiar with Ceja's Clean Architecture, where use cases are classes that implement the Command Pattern. Shvets defines the pattern intents as follows: Encapsulate a ...
3
votes
1answer
209 views

Is it an anti-pattern for Swift functions that take in a sender to have a label for that parameter?

This is something I see all over Cocoa: func someAction(_ sender: Any) which is called like: someAction(someObject) This can be very confusing to me. The infamous example is in NSView subclasses: ...
4
votes
1answer
1k views

Swift-like extensions in Java using inheritance

After picking up some Swift skills with Java as my strongest language, one feature of Swift that I really like is the ability to add extensions to a class. In Java, a pattern I see very often is ...
4
votes
2answers
2k views

Should I use Lua for writing config files?

I heard that Lua is great for configuration files, so long as you are secure about it. Lua has been used as config files by programs such as awesome and (recently) conky. However, I also heard that ...