Questions tagged [anti-patterns]
A programming anti-pattern is a commonly used solution to a specific programming problem, often claiming being an actual design pattern. But such a solution usually leads to adverse effects on an application scalability, testability and maintenance.
431
questions
0
votes
0
answers
24
views
Is putting a global state in useEffect deps considered bad practice?
I recently stumbled upon an issue where a value that is stored in global state(redux) is watched in React component, especially in useEffect hook dependancy.
To be specified, it was an authenticated(...
0
votes
1
answer
47
views
Is a forEach in redux reducer an anti-pattern?
I have a forEach loop which checks if a certain attribute of data coming in includes '/' if it does im replace the '/' with '-', i was wondering if that is valid redux code or im creating some sort of ...
3
votes
1
answer
6k
views
How to fix React WArning : Can't perform a React state update on an unmounted component
Whenever if there is any asynchronous task performing related to component and that component unmounts then React generally gives this warning -
Can't perform a React state update on an unmounted ...
1
vote
1
answer
208
views
Is there an alternative to Template Method pattern when using common logic?
I have a problem. Most of the solutions in the project follow the Template Method design pattern. At the same time, along with the complexity of business logic, solutions are becoming more and more ...
0
votes
1
answer
72
views
Is folder name shadowing 3rd-party package name or Python module name is an anti-pattern?
Consider the following (very simplified) project structure:
project/
src/
collections/
validators/
foo/
bar/
The "collections" sub-directory name shadows ...
1
vote
2
answers
264
views
C# - How to inject new instance of dependency to a class which get instantiated once in the app lifetime?
Here is a class which will be instantiated only once through out the lifetime of the application
public class SampleClass //instantiated only once
{
public void DoOpertation()//will be called by ...
1
vote
1
answer
40
views
Does Information Expert pattern contradict Service Layer Pattern?
While reading about GRASP patterns I stopped at Information Expert, which states that behavior on classes state should be within that same class. But that is a complete opposite with Service Layer ...
0
votes
0
answers
30
views
Fighting back sequential coupling with correct design pattern
everyone reading this. First and most important, thank you for spending time on this.
So now let me go straight to the question.
Recently I received a homework where I have to deal with sequential ...
0
votes
1
answer
570
views
Best practice for an optional return value
Suppose a function cannot compute a valid return value. For example, a dictionary lookup may fail to find a key. What are the best practices for such a situation when a function returns one or no ...
0
votes
0
answers
26
views
Patterns for fetches memoizations in React
In my app I have a folder "api", in which I have all the necessary methods to communicate with my backend.
For example:
api/db/users/getUserData.js
export default async (userId) => {
....
0
votes
0
answers
79
views
Does this component fit into the Anti-Patterns of React?
How can I rewrite this component so it doesn't go against the rules of React? I'm calling the function renderButtonType() inside of the render(). Is that the correct way to conditionally render the ...
0
votes
2
answers
130
views
Why inject the entire DbContext instead of just the necessary DbSets?
I've seen a lot of projects whether the entire DbContext is injected in a class:
public class MyClass
{
public MyClass(MyDbContext context)
{
...
}
public void DoStuff()
...
0
votes
3
answers
539
views
Is it an anti-pattern to use variables the outside of React function component?
Is below case an anti-pattern in React?
Variables and functions might be declared outside a React function component for some reasons. For example, an timer ID and others could be used as below:
...
7
votes
1
answer
1k
views
What is the "Smart UI Anti-Pattern"?
In his book, Implementing Domain-Driven Design, Vaughn Vernon states,
When there are User Interface views that render the model and drive execution of its behavior, these are also inside the Bounded ...
0
votes
2
answers
72
views
Best way design and generate unique strings from an array of objects for mapping
The problem I am trying to solve is how best to generate a unique string from a set of question/answer strings.
So say an end user fills out a questionnaire and answers the following:
[
{
...
1
vote
1
answer
89
views
React Context: Nested re-use/enhancement (anti-pattern?)
I would like to know if it is an anti-pattern to create nested context providers (the same context) and progressively extend the data. So, using the current context and enriching/overriding it from ...
0
votes
1
answer
57
views
Is this an anti-pattern/code smell? - Using enum/class of consts to access class properties with [] instead of using dot property
class FruitFields {
static const NAME = "name";
static const DESCRIPTION = "descriptionText";
}
class Fruit {
final string name;
final string descriptionText;
Fruit(required ...
0
votes
1
answer
85
views
Is self injection a good practice? Same class injection programming pattern in PHP
Is injection of the same class a good practice?
I am using self-injection for years to isolate methods during PHPunit testing:
class Meter extends Model
{
use SomeTrait;
protected self $self;
...
-3
votes
1
answer
690
views
singleton is design-pattern or anti-pattern? [closed]
singleton is design-pattern or anti-pattern??
0
votes
0
answers
101
views
Is two way classes association bad?
I was developing one tool, and noticed what my classes use "two way association".
Objects of class A have a pointer to B, and B have pointer to A. I tried to find out, is that a bad design ...
1
vote
1
answer
157
views
Is "static Domain helper class" Ambient Context Anti-Pattern?
As defined in the Manning book by Steven van Deursen and Mark Seemann, "Dependency Injection Principles, Practices, and Patterns" (which I recommend as must-read), there is one specific anti-...
4
votes
1
answer
194
views
Is inheriting from the EventEmitter an antipattern?
It appears to be common practice to inherit from the EventEmitter if you want your class to support events.
For example Google does it for Puppeteer, the WebSocket module does it, mongoose does it, ......
1
vote
1
answer
794
views
Get value of field with lombok builder
Is it possible to retrieve the value of a field on a builder which was generated by lombok?
final var builder = Something.builder();
try {
// ... something that might break
}
catch (Throwable t) {...
0
votes
0
answers
55
views
How can I eliminate a "rank() over (...order by timestamp)" pattern in Hive?
This pattern seems very inefficient:
SELECT
*
FROM
table1 a
inner join (
SELECT
*
,rank() over (partition by orderNum order by orderUpdateTime) rnk
) b ...
WHERE
b.rnk = ...
0
votes
2
answers
602
views
Dao in Usecase. MVVM or Clean Architecture anti-pattern?
In our "SearchUsecase" we have access to "ShowFtsDao" directly.
Does it violate the Clean Architecture principles? Does it violate the MVVM architecture?
Assuming our intention is ...
0
votes
2
answers
81
views
Refactoring Promise code to remove async/await in new promise constructor
I had been reading and saw that it is an anti pattern to use async/await in the promise constructor.
I had the following code in my current project and I wish to refactoring it but not very sure how I ...
0
votes
1
answer
197
views
Python decorator taking additional argument anti-pattern
Is adding an argument to a function through a wrapper a python anti-pattern? I want to add a wrapper that saves the output of many functions to a location, so a wrapper seems to make sense. However, ...
1
vote
1
answer
317
views
Counting lines or enumerating line numbers so I can loop over them - why is this an anti-pattern?
I posted the following code and got scolded. Why is this not acceptable?
numberOfLines=$(wc -l <"$1")
for ((i=1; $i<=$numberOfLines; ++$i)); do
lineN=$(sed -n "$i!d;p;q" &...
0
votes
1
answer
67
views
Is async code in a Promise always an antipattern?
I see from this question that it can be an antipattern to mix Promises with async code.
Does this, however, apply in all cases?
I can't see an easy way to avoid combining them in the following code:
...
1
vote
1
answer
25
views
What is this anti-pattern? Invoking a function for a latent effect
Is there a name for this anti-pattern? The best way I can describe it is "invoking a function for a latent effect, not for its primary purpose".
Function A does X and Z
Function B does Y ...
0
votes
1
answer
84
views
Is it an anti-pattern to use the suffix "Template" for the class name of the template method pattern?
I am using the template method pattern.
My abstract class has a skeleton method processing iteration and logging.
like this:
abstract public class ImportingTemplate implements Importing{
...
2
votes
0
answers
59
views
data.table anti-pattern when adding/modifying a new column [closed]
I am rather new to R and working on an existing code base heavily using data.table. I understand one of the correct way to add a column or modify an existing one is:
my.table[ , new_column := "...
1
vote
0
answers
56
views
Is using const == thread safe a bad practice [duplicate]
I just listened to this talk about how const actually means bitwise immutable OR thread safe in and after c++11. Furthermore we should guarantee const functions to be thread safe. This is all well and ...
1
vote
1
answer
563
views
Is synchronous communication between services anti-pattern in microservices?
I am somewhat new to microservices. I am currently developing an application using microservices and I am using both synchronous and asynchronous communication methods. Recently I saw few article ...
1
vote
1
answer
120
views
Is this an anti pattern?
Currently I am confronted often with code that follows the pattern demonstrated by the code bellow. It is kind of a strategy pattern.
I am not fine with this, it feels somehow smelly. It breaks the ...
5
votes
2
answers
508
views
Is extending a widget really an antipattern?
I've read in couple places that extending a Flutter widget is an anti-pattern. Is that true?
I've used widget subclassing to cut down on nesting by subclassing the widget I'm removing and put its ...
4
votes
3
answers
206
views
Bad idea to put a dom operation inside a redux reducer?
I have several actions which use the same reducer, and instead of having a dom operation in each of those actions, I want to just add it once inside my shared reducer. I know reducers are to be pure (...
1
vote
1
answer
126
views
Is returning a void response for Service APIs a good practice?
I am planning to build APIs to perform CRUD operations.
I have the following APIs:
CreateEntry
UpdateEntry
For CreateEntry API, I am accepting CreateEntryRequest and CreateEntryResponse as request ...
0
votes
0
answers
70
views
What is this data referencing anti-pattern called?
I have a question related to a kind of duplication I see in databases from time to time. To ask this question, I need to set the stage a bit:
Let's say I have a database of TV shows. Its primary ...
0
votes
1
answer
368
views
React CTA with Modal in DropDown Pattern
I'm using MaterialUI's ButtonGroup as a drop down menu and having a pattern issue trying to create a series of CTAs which I can easily swap around in it; where all of the components are reusable and ...
3
votes
2
answers
371
views
How does the initialization of classes in Scala work?
The code below throws a java.lang.NullPointerException because the trait is initialized prematurely.
trait DummyTrait {
def intSeq: Seq[Int]
require(intSeq.exists(_ > 2))
}
object Dummy ...
2
votes
1
answer
65
views
Is creating a function to do a small repeated task an anti-pattern?
I am trying to learn best practices for programming and want to keep my code as clean as possible, but also maintainable. For example, I am running a program that waits for each element to be created. ...
1
vote
0
answers
157
views
Are functional components that are class properties an anti-pattern in React?
There's a few places in an existing codebase that I work on that has a functional component as a class property on a React component to avoid having to pass state, props, and callbacks to a child ...
-1
votes
1
answer
48
views
Passing current service object to domain will be a anti pattern for DDD?
I have service which is getting domain from repository and passing its own instance to the domain for some external dependency. Can it become anti pattern? RichDomainModel suggests to pass dependency ...
1
vote
1
answer
186
views
Factory (method) pattern and callouts to other methods or other factories in a deep/long chain
There is a huge discussion at my work what a factory pattern is.
The main discussion point is whether one within a factory under creation of the object also may branch out calls for population of its ...
0
votes
1
answer
36
views
Is there an established name for this anti-pattern?
Quite often I see code that use redundant properties for data, when one value could have been calculated on the fly from two others. To me it is an obvious anti-pattern, as it makes further work on ...
0
votes
1
answer
319
views
React ref anti-pattern for Popups
Recently I've found myself implementing a ref based pattern that seems to go against react documentation advice.
The pattern goes like this :
type Callback = () => void;
type CallbackWrapper = {...
1
vote
1
answer
400
views
clang-tidy fails bugprone check
I'm experimenting with clang-tidy using the following file:
#include <stdio.h>
int main(int argc, char **argv)
{
int i=2; int j=1;
if (argc = 5) { return 2; }
while (i<argc) { j+...
5
votes
1
answer
209
views
In JavaScript, is `return someValue` in a generator function an anti-pattern?
In the following, the .next() can show the last value: { value: 3, done: true }:
function* genFn() {
yield 1;
yield 2;
return 3;
}
const iter = genFn();
console.log(iter.next());
console....
-3
votes
1
answer
50
views
How can I use patterns to process data in a specific way in ArrayList in Java? [closed]
There are several strings in my array list and some of them start with a specific prefix -for example ("AFI"). I want to remove these strings from the array list. Other strings contain more than two ...