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.

1
vote
2answers
65 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
129 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
65 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, ...
1
vote
2answers
97 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
860 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 ...
0
votes
2answers
245 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
444 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
153 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
595 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
364 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
35 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
571 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
399 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 ...
0
votes
2answers
2k 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
348 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
697 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 ...
154
votes
7answers
24k 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
333 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....
116
votes
27answers
22k 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
306 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
524 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
276 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
211 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
342 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
445 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
289 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
358 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
727 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
1k 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
369 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 ...
1
vote
4answers
769 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
433 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
280 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
205 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 ...
5
votes
2answers
318 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 ...
5
votes
2answers
181 views

Update model chain on event driven pattern

What is the formal name for this specific problem scenario in an event-driven architecture, and what are the common approaches to handle it?: After an action or event is dispatched, several ...
-3
votes
5answers
187 views

How to convince others to effect change? [closed]

I'm low man on the totem pole (consultant) who was pulled into a project for a large organization. How do you explain that this large organization practices zero industry standards and follows no ...
0
votes
2answers
426 views

Is it acceptable to escalate a software error to HTTP 500?

Should an error 500 only be thrown by the web server, or is it acceptable for your program to throw one itself? try { some bad code; } catch (Exception) { set_header_code(500); set_content_type(...
1
vote
1answer
1k views

Why singleton is an anti-pattern? [duplicate]

Many articles in Internet say that singleton is an anti-pattern, because it makes debugging more difficult. However I don't understand why debugging a program with a singleton object is difficult. ...