Questions tagged [dry]
Don't Repeat Yourself, a software development philosophy which aims at reducing redundancy and code repetition. Questions regarding how to refactor code are better suited on codereview.stackexchange.com
2,218
questions
0
votes
0
answers
50
views
How do you idiomatically DRY up rust code without upsetting the borrow checker?
Context
Coming from OOP I'm finding as I implement various traits and functions on my structs, I want to abstract bits and pieces of them out. But whenever I do, I run into borrow checker issues. I'm ...
0
votes
1
answer
53
views
Does it makes sense to DRY a non-async method using its async version? [duplicate]
Trying to do so involves using the weird syntax of GetAwaiter().GetResult().
Beside that fact, it works; but does it sucks to do so? If yes, then why?
Original:
internal static ISector Read(ISector ...
3
votes
1
answer
69
views
How to not copy the code, but create one method?
I have a method
private void positionMagican() {
int x;
int y;
boolean magicanIsCreated;
magicanIsCreated = false;
while (!magicanIsCreated){
x =...
0
votes
0
answers
44
views
Repeating validations on DTO's
I have recently started learning Asp.net core. I came across DTO's concept. I am using Attributes for validation. I have read online that validation on DTO's is considered common/good practice on ...
1
vote
8
answers
306
views
Avoid repetition of strings in SQL query
I have a SQL query where the list of strings is repeated twice: ('foo', 'bar', 'baz', 'bletch'). What is the most maintainable method to avoid such repetition and make this code more DRY?
I am not ...
0
votes
1
answer
98
views
Next.js & TailwindCSS how to re-use styles on a component in the same component file?
Working on my first Next.js 14 project and quickly found out the theme I'd authored in Chakra UI will not work with server components (reference: Support for NextJS 14) until Chakra UI version 3 is ...
0
votes
2
answers
120
views
How to rebuild StateProvider in RiverPod Flutter
recently I was reading about Riverpod State management in Flutter, and I started using it in my App, I wanted to give a random List of image paths when I press refresh button on my Ui,I made a ...
0
votes
1
answer
69
views
Dry validation. How to send param in to macros
json (simple example):
{
"person": {
"birthday": "1990-10-10"
},
"achievement": {
"date_appr_r": "2022-05-21"
}
}
My ...
0
votes
1
answer
36
views
How to generalize a dynamic list component in React
I am creating an app in React native where I will be using <FlatList> component multiple times.
Now, all the lists are very similar and the only dynamic element is the data inside the lists. The ...
0
votes
1
answer
35
views
Avoiding repetitive checking of function output before storing into a dictionary
I've a repeating code block of iterating through inputs, checking some functions to return a list and the populating dictionary if the function did return a list, e.g.
def some_func(i):
"&...
0
votes
0
answers
112
views
How to encapsulate adding and removing of a temporary event handler in C#?
I 've got a section of code that may raise an event c.MyEvent (actually, lots of those). Before this section of code is executed, I want to add some Handler MyHandler to the event. The same handler ...
-1
votes
1
answer
44
views
Reuse controller paths for a Spring Boot Controller
We have a Person class and in our Spring boot Controller for the Person class we have a few functions that have a path that starts with
/person/{id}
However, we want to reuse all those functions for ...
-1
votes
1
answer
71
views
How can I avoid repeating myself in doxygen comments (unfortunately without member groups)?
I'm documenting a (C++) library of mine with doxygen comments.
In this library, I have some cases of overloads of the same function, doing the same thing but with different inputs, e.g.
void ...
0
votes
0
answers
15
views
Approach to display links by role
Imagine you have a navbar with over 50 links (including dropdowns), and there are about 7 user roles within the app. I won't focus on any specific programming language, but rather on the most ...
0
votes
1
answer
64
views
JS: Combining multiple independent promises into a single function
I have the following code appearing in many of my JavaScript files:
import { doA, doB, doC } from 'asyncDoer'
// ... other stuff
let isDoneA = false
let isDoneB = false
let isDoneC = false
doA.then(...