2,223 questions
- Bountied 0
- Unanswered
- Frequent
- Score
- Trending
- Week
- Month
- Unanswered (my tags)
2
votes
3
answers
113
views
How to refactor repeated conditional logic for multiple similar elements in JavaScript?
I have a restaurant ordering app where I'm displaying order items. Currently, I have repetitive code for each menu item (pizza, hamburger, beer).
Current code (simplified):
function displayOrder(...
3
votes
1
answer
97
views
Nested ordered list items to any depth
Is there any cleaner/DRYer way to get nested ordered list items (e.g. list item number 2.4.1.7.8.2.9) that are indented properly, rather than defining every single level manually up to 10 levels deep?
...
2
votes
1
answer
217
views
How to reduce the redundant code in a header file?
I'm writing unit tests to test C++ classes. The functions below test to see how a function handles an exception. The code below does work, but it is very redundant, I would prefer to have 1 template ...
0
votes
3
answers
359
views
How are headers not a DRY violation? [closed]
In C++, if you make a separate .cpp file to keep classes separate like you might in Java, you also have to make a .h file declaring everything you want to make.
I understand why you must, since the ...
-1
votes
1
answer
80
views
Prevent duplicate boilerplate operator overloads [duplicate]
This is a follow up of this question, which might have been a XY problem. Anyhow, that was closed within a few minutes, before I could get any real help.
In our large code base (measurement processing ...
1
vote
2
answers
250
views
Prevent duplicate operator overloads implementations
In our large code base (measurement processing application) we've had bugs where values were mixed up because everything is a double. So we decided to try-out strongly named types for things like ...
1
vote
1
answer
152
views
How do I not-repeat-myself with this redundant method name prefix?
I'm writing a library which has a queue object (not std::queue and not usable as a C++ container). On this queue, we can enqueue commands, with arguments. Let's say the commands are foo, bar and baz, ...
0
votes
1
answer
51
views
Overloading + Operator in C++ for Symbol Class and Avoiding Code Duplication
I am creating a binary tree representation of a mathematical expression for performing differentaiton and integration on it.
I am trying to overload the + operator for my Symbol class. It works fine ...
0
votes
1
answer
60
views
How to prevent duplicate code for exception handling in Python [closed]
What is a Pythonic way to not have duplicated code for exception handling?
In a real code base, it is not 2 / 0, but reading or writing from an async socket, and I have more exceptions to catch, ...
0
votes
1
answer
57
views
How can I avoid interface repetition in Python function signatures and docstrings?
I'm looking for a standard, lightweight (preferably built-in) way to handle the problem of interface repetition—where the same parameters (with annotations, defaults, and docs) are repeated across ...
0
votes
1
answer
101
views
Can a generic Blazor Component handle multiple classes with the same structure?
I have created a Blazor Component to handle editing a database record which is defined by a class.
I would like this component to be reused to edit other records - that have the same structure, but ...
1
vote
0
answers
100
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
80
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 ...
aybe's user avatar
- 16.8k
3
votes
1
answer
87
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 =...
2
votes
7
answers
792
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 ...