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.

2
votes
4answers
2k 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
452 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
338 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
2k 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
246 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: ...
5
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 ...
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 ...
4
votes
2answers
219 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
198 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
469 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. ...
0
votes
1answer
1k views

AMQP routing-keys naming anti-patterns when using topics

I'm working on the specification for building a web services platform and AMQP is the messaging protocol used for the interaction between the components of this platform. I'm using topic exchanges ...
2
votes
1answer
122 views

How would one avoid circular object references when each element in a collection can possibly interact with any other element?

I have a class called Canvas that acts as the container for a number of Rectangle. The Rectangles have the following behavior: They can be moved within the Canvas. They can be resized. They may not ...
208
votes
10answers
23k 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 ...
2
votes
1answer
5k views

Using singletons in Python (Django)

I was suggested to define a singleton in Python in the following way: class Controller: pass # ... controller = Controller() However, this way, controller cannot be replaced with a derived ...
3
votes
2answers
940 views

Am I breaking SRP when I inject Factory pattern with Repository layer?

In the context of MVC sometimes I find myself creating a Factory and injecting the factory with Repository. While it is certainly possible to use Repository as layer inside the Factory, I wonder if ...
0
votes
0answers
197 views

A modification of singleton pattern

"Singleton" is widely considered anti-pattern ("bad" in everyday language). What about this alternative modified singleton pattern? An object constructor for our class ensures that at any given ...
1
vote
3answers
236 views

How to gently steer a giant PHP app toward better practices? [duplicate]

So I'm responsible for maintaining and enhancing a PHP codebase that runs to around 1,100 files and 120,000 lines of code. In general, it's not terrible, although since it was written over some 10+ ...
1
vote
1answer
1k views

Is using __import__('module_name') an antipattern in Python?

I'm currently refactoring a Python 2 project which includes the ability to add or remove plugins, which are Python modules implementing a given API. The main app accesses add/remove/update hooks in ...
43
votes
11answers
5k 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 ...
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 ...
22
votes
1answer
6k 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 ...
0
votes
1answer
359 views

Is there an official name for the “one object disease” anti-pattern (iterative single object operations on databases, services etc.)?

It is caused by the naive programming paradigm: focus on just a single object, do something with it, and if you have to work with many objects, you loop, iterate and traverse, repeating the operation ...
4
votes
1answer
509 views

What are best practices when it comes to extensions in Swift with reusability in mind?

I like the Swift way of trying to eliminate unintended consequences wherever possible. Whenever there is a change to the language that deprecates something I have been doing for years, it forces me to ...
7
votes
4answers
2k views

Test cases do all the work through helper method — bad practice?

Consider a test suite like this: public class MyTestSuite { @Test public void test_something() { testHelperMethod("value11", "value12", "value13"); } @Test public void ...
1
vote
3answers
421 views

Is synchronously inspecting a promise an anti-pattern?

ES6 native promises do not allow you to synchronously check if they're resolved/pending/failed or to extract their value. I sometimes need this functionality and thus I have to code it manually. Is ...
1
vote
1answer
251 views

Service/component based application in Java

I have a Java project whose architecture is quite component-oriented, and I am wondering if this is a common way to organize code which rules/patterns are used, if there is a name for this coding ...
32
votes
3answers
14k 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 mutating ...
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 ...
5
votes
2answers
2k views

What alternatives to a singleton are there for a class which only can have one instance?

I need to represent an abstraction over various parts of the hardware for a game. I'm trying to decouple the code that does things like manage the logic of the game from the code that is API/platform ...
6
votes
2answers
2k views

Is using for loop syntax for a “with(variable)” block an anti-pattern?

I fooled around with for-loops, remembered the with keyword from delphi and came up with following pattern (defined as a live template in IntelliJ IDEA): for ($TYPE$ $VAR$ = $VALUE$; $VAR$ != null; $...
1
vote
2answers
100 views

Explaining concepts [closed]

How can I explain a concept when I don't know its name or any formal reason for it? The reason I ask is this... A new programmer has entities with a property title in his system. He uses the title to ...
18
votes
1answer
11k 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(...
0
votes
0answers
115 views

Excessive LINQ chaining - Is it considered a code smell, and why? [duplicate]

I am in a current iteration between design and implementation, and ended up with the following "one-liner": IEnumerable<Channel> ActiveChannels = Receiver.AcquisitionInfo ...
1
vote
1answer
168 views

Lines of code that take on too much responsibility [closed]

Intuitively, I know that (in terms of a maintainable, understandable codebase) the following code is bad practice var foo = fooFunc(barFunc(),wooFunc(chewFunc())); and might be better stated as var ...
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 ...
7
votes
3answers
4k views

Is enum order sensitivity an antipattern?

Is it an anti-pattern to depend on a particular order of an enum's instance declarations? For example, consider: public enum CompassPoint { North, East, South, West; } These points ...
0
votes
2answers
242 views

Is there a name for this data structure pattern consisting of a list of dictionaries each with one entry, consisting of an object? [closed]

There is a data structure idiom that looks something like this: [ { obj_1_id: { key1: value1_1, key2: value2_1 } }, { obj_2_id: { key1: ...
4
votes
4answers
510 views

Using a one-shot class to store not-quite-global variables

I sometimes find myself writing classes (in Python, in my case) that are used like this: MyClass(some_args).go() In other words, there's only one method in the class that any external code would ...
5
votes
2answers
317 views

Is there a name for the anti-pattern of having low-level components controlling higher-level ones?

For example, suppose I had a pageControl UI class and a searcher business logic class with the following : pageControl.js function searchButtonClicked() { // call business logic class method when ...
11
votes
8answers
3k views

Is turning UI (or other) features on and off based on dates-a code smell?

We have an awful system written in ASP.NET 2.0 that we need to add some functionality to. The problem is that a certain product has UI features that have to be turned on for business initiated after a ...
8
votes
3answers
3k views

Design Pattern - DLL per Strategy

I usually found myself designing my application in the following way: One DLL containing interfaces for a desired subsystem. For example, Company.Framework.Persistence.dll. One new DLL per each ...
-1
votes
1answer
76 views

Experimentally determined timing of function/method calls vs locks, signals. Anti-pattern name?

Here is some pseudocode and paraphrased comments: // Allow time for screen to start before content reset. // Delay time determined by testing with platform version 5. delayCall(0.01, contentReset()) ...
2
votes
1answer
142 views

Should I represent physical accessories of a system as classes in software?

I am redesigning a system comprised of a data-acquisition unit and a lot of different sensors (voltage sensor, angle sensor, pressure sensor, etc.). In the software domain model, there is a base ...
1
vote
1answer
576 views

How to avoid big class complexity while keeping encapsulation?

I'm developing a PHP library to work with big numbers (at this moment only with a "Decimal" class, but I want to add new classes, to handle Integers, Rationals, and Complex numbers). In any case, the ...
3
votes
2answers
329 views

What principle is violated by having a button do two radically different things or screens act radically different depending on the situation

I've come upon a situation several times in my career when previous developers have done something funny. They will make a control (button) function radically different depending on how the screen ...
3
votes
1answer
680 views

OOP - How to refactor a “pyramid architecture”

Unbeknownst to me while I was building it, I built a "pyramid" architecture. I did not realize this until I laid it out in my new Visual Studio 2013 Layer Diagrammer. Each layer depends on the layer ...