Questions tagged [dry]
DRY is short for "Don’t Repeat Yourself". This paradigm advocates to avoid code and data redundancy.
148 questions
-1
votes
2
answers
146
views
How to handle complex logic, avoiding recalculation for performance reasons?
let's say we're building an Ecommerce Marketplace.
We have Sellers and each Seller has Products.
We want to display a list of available Products across all Sellers to Buyers.
But, we only need to ...
7
votes
2
answers
2k
views
How can I make code that is both DRY and fast where intermediate values in a calculation may or may not be needed?
How can I make DRY (lacks repetitive patterns) code that also avoids inefficiencies from using intermediate values in a calculation that might not need to be used?
Here is an example:
In this code, I ...
1
vote
3
answers
372
views
How to avoid duplicating Create and Update UIs in CRUD apps
For most apps I've built which deal with CRUD operations, I end up two very similar UI pages: one for the creation of the object, one for updating it.
An example would be StackExchange's UI for ...
1
vote
1
answer
3k
views
How to handle duplicate validation logic with CQRS pattern
I am implementing a CQRS pattern in ASP.NET Core with MediatR, and I am wondering what the general consensus is for handling duplicate validation logic for queries/commands which operate on the same ...
14
votes
3
answers
3k
views
Should I choose repeated code in unit test or test logic? Can I avoid both?
When writing unit tests, I feel that there is a trade-off between code repetition and test logic.
Example of my current (likely flawed) approach:
To test this function (overly simple function for ...
2
votes
5
answers
655
views
Do db calls in constructors lead to more DRY code?
It recently came to my attention that its best practice to avoid database calls in constructors. I feel like this means you end up repeating unnecessary code, thus the code is less DRY?
For example, ...
1
vote
3
answers
431
views
How to split out shared authorization logic across spring microservices
Currently working on a project where we have multiple services that all need to consume the same authorization service when their endpoints are hit. Right now we have the authorization boilerplate ...
-4
votes
1
answer
93
views
How to use DRY methods with OS commands with Python and classes
My goal is to learn more about OOP patterns and use DRY principles. I am trying this for wrapping an os command that interacts with a database using classes:
This works fine:
import subprocess
class ...
53
votes
10
answers
8k
views
How should I test "Glue Functions" without testing that "the code I wrote is the code I wrote"?
I usually write my code in a test driven style. I write tests as specifications and then my code. It's great and useful.
I always try to ignore implementation when testing and only test behaviour. I ...
24
votes
11
answers
7k
views
The Don't Repeat Yourself (DRY) principle in documentation
Dave Thomas, the author of the Don't Repeat Yourself principle said:
DRY says that every piece of system knowledge should have one
authoritative, unambiguous representation. Every piece of knowledge ...
2
votes
1
answer
317
views
Selective method inheritance
I have a lot of classes that are just a CRUD interface for microservices. They only have a param for the endpoint and some of the methods get_list / get_item / create / update / delete / activate / ...
3
votes
1
answer
466
views
DRY principle vs decoupling (business from GUI)
Say I have a business model called Vehicle. Vehicle has many fields but to keep it simple say it looks like:
public class Vehicle {
String ownerName;
String brand;
FuelType fuelType;
}...
4
votes
5
answers
276
views
Approaches for comment duplication
For code, we know approaches like DRY and we tend to extract common functionality. What approaches are recommended for comments? Perhaps it's a really open question, so I'm going to go with my ...
-4
votes
1
answer
417
views
Best way to structure reusable code using Node.JS, EJS, and front end JS?
I'm more or less learning the MEAN stack (have yet to start on Angular, so currently using straight vanilla JS for front-end) and part of what I'm building for my portfolio is a drag-and-drop form ...
0
votes
2
answers
216
views
DRY Violation for Logical Code Organization and Readability
I have a block of code that branches into 2 pathways, let's call them the "simple" and "complex" branch, based on user input.
Either the simple or complex logic has 4 steps, let's call them A, B, C ...