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 [dry]

DRY is short for "Don’t Repeat Yourself". This paradigm advocates to avoid code and data redundancy.

1
vote
1answer
97 views

What is the best way to handle the scenario in C++ where there are two methods that are identical, except one is const?

I am currently working on a program in which I encountered an issue (not for the first time) where I have two acessor methods for a data structure. The methods are identical, except one is const and ...
0
votes
1answer
142 views

Keeping steps in sync of long running process and creating common layer for code repetition

I have 1 long running process wrapped inside a method and it is for 2 different types like below: Type1 Type2 Code: public interface IBaseType { MyResult LongRunningProcess(int jobId,...
-2
votes
3answers
293 views

Are there any well known alternatives to the SOLID principles for OO programming? [closed]

I´m looking for some kind of better compilation of principles which takes the old basic concepts (DRY, KISS, etc...) and applies them to OOP related concepts like abstract clasess, interfaces etc... ...
2
votes
2answers
172 views

How to avoid code duplication in two similar projects?

We have a website with a lot of functionality, and we now start another one, which should have a lot of common code with the first one. What would be the best approach to avoid code duplication? ...
4
votes
5answers
480 views

Is copy and paste the head of for-loop (e.g.:for(let i=0;i<something.length;i++)) violating DRY principle?

For example, in my project, I often found some head of for-loop appears many times, eg: for(let i=0;i<SharedData.students.length;i++){ SharedData.students[i].something=..... } if(isReset){ ...
1
vote
1answer
60 views

How to remove code duplication in Web API versioning

I'm working with ASP.NET core web API project, where I have 8 controllers, multiple DTOs being used for request and response and mappers to map models(also used in the web app) with DTOs. Recently, ...
1
vote
2answers
159 views

DRY or not to DRY in SDK

I'm making contribution to an opensource project by one of the leading hypervisor providers and I have noticed that there is awfully lot of repetition. Below is what I mean by it, imagine that they ...
7
votes
6answers
619 views

Is duplicating files to avoid programming branching a good or anti pattern?

for example, suppose I need to play different sounds according to "grade": file list: fairSound.mp3 goodSound.mp3 excellentSound.mp3 code: showResult(grade){ if(grade==0 || grade==1){ ...
-1
votes
1answer
63 views

My action creators and reducers all mostly look the same - is this a code smell?

Most of my redux actions are 'fetch some data from the database, here's the authentication token', and they for the most part look the same, like this: action creator export const fetchDashboard = ...
0
votes
1answer
56 views

ReactJS - proper way to handle a responsive design approach?

I've always used CSS and media queries when it comes to responsive design. I've been developing in ReactJS for a while, but I feel my approach to responsive design is sloppy. I find myself using a mix ...
14
votes
5answers
548 views

Is it possible to apply DRY without increasing coupling?

Assume we have a software module A that implements a function F. Another module B implements the same function as F'. There are a number of ways to get rid of the duplicate code: Let A use F' from B....
5
votes
3answers
185 views

How to handle repetitive mallocs/frees in a DRY way in C

So I have a function which is like a constructor for my structure: MyStructure* CreateMyStructure(...) { MyStructure *my_structure; double *data; int *colind, *rowptrs; data = malloc(...
2
votes
1answer
307 views

Is 'Keep it looks similar to sample code' a valid reason to prefer WET over DRY principle?

For example, for oauth, I may need to copy and paste oauth and oauth callback code like it (assume Client is the framework I use, I don't use real framework like google because I want to simplify the ...
14
votes
3answers
359 views

Code coupling introduce by DRY and OOD

I'm looking for guidance about DRY vs Code coupling. I do not like to duplicate my code and I also do not like code coupling between unrelated modules. So I refactor duplicate code if I find ...
0
votes
1answer
58 views

Is creating near duplicate partial views solely for populating html elements with Ajax returns violating DRY?

Maybe anti-pattern is a better word for this question. I do not know, but I mean a violation of DRY. Id like to reuse a partial view, and I can, but that partial view has other things in it I don't ...
7
votes
4answers
611 views

Don't Repeat Yourself Vs Single Point Of Failure in authentication

In my work we've been tasked with implementing two factor authentication across a number of our web applications which currently share a credentials database (asp.net forms authentication) but have ...
0
votes
0answers
62 views

At what point should I turn several similar programs into a service? (If at all)

At my place of employment, we have a need for several file listeners. These are generally long running programs that wait for files to drop in a specific directory. The way the files are handled ...
1
vote
4answers
283 views

Put conditional logic inside method for DRY, or keep it outside for readability?

Take the following example which loads an interstitial ad every 10 times user does XYZ in the app, under certain conditions. It is called in multiple places in the code base: public class AdHandler { ...
2
votes
2answers
54 views

Test on each Authorization endpoints?

I'm writing an API server. The framework we're using is Rails + Pundit + graphql-ruby, but I guess this question is framework-independent. We have authentication + authorization implemented on the ...
4
votes
1answer
59 views

Organizing Ad-Hoc Tooling in a Muti-Repo Structure

Imagine you have the following scenario. Your organization deploys some app core to its mission. For example if you're Stack Exchange, this might be the customer facing web server. Let's also say you ...
3
votes
5answers
405 views

Does my code violate DRY principle?

Suppose that I have two services Person Service and Company Service and I want to maintain links between them for example a Person is linked to Company because he works there or he owns the company ...
36
votes
3answers
10k views

Is “composition over inheritance” violating “dry principle”?

For example, consider I have a class for other classes to extend: public class LoginPage { public String userId; public String session; public boolean checkSessionValid() { } } and ...
0
votes
4answers
150 views

How to insert code in a method in a derived class [duplicate]

I have a base class with a method called Update: Start Update Code block 1 (An If statement) Code block 2 (Setting a variable based on the If result) Code block 3 (A switch which is ...
1
vote
0answers
101 views

Can we break CQS to get some DRY?

In our codebase we have a lot of controllers with a very similar structure: @my_model.update_owner(something) if @my_model.update_attributes(params) return render_object(@my_model) else ...
1
vote
3answers
149 views

Reduce return type repetition of functions

As an exercise, I recently implemented a simple settings reader class which reads setting values from an INI file into an std::map<std::string, std::string>. The reader method looks like ...
6
votes
6answers
866 views

DRY principle often makes my code more complicated and/or more difficult to understand

This often happens in my projects. Sometime I have this part of code that is very similar to this other part, yet a few lines makes it complicated to keep the code clean and without duplication. Here ...
-1
votes
3answers
280 views

Constructor from interface with minimal repetition

Preface In an application that is separated by layers or distributed by services it is common to have classes that are very closely related data-wise, but which we wish to have loosely coupled. My ...
4
votes
3answers
167 views

Changing bot application state (Starting → Started → Stopping → Stopped)

I am developing a bot which I need to start and stop at will. I have 2 buttons in my form, StartButton and StopButton which change the state. The Bot has 4 possible states: starting, started, ...
0
votes
1answer
505 views

How can you reuse code for similar functions on AWS Lambda?

I have 3 Lambda functions that do very similar things: scrape data from different sections of a website. Each function returns a collection of objects that have similar properties. The method of ...
0
votes
1answer
95 views

Dry refactoring against database

Our database has an Attribute table and a WorkItem table that are in a many to many relationship using a WorkItemAttribute table. The WorkItemAttribute table contains the foreign keys for each and a ...
0
votes
2answers
109 views

How to share code among different top-level repositories?

My company has one repository that contains five top-level projects, which are all different "services" (that being the flavor of the month). Even though they're all in a single repository, they're ...
3
votes
2answers
233 views

I keep bouncing from “god function” to “tiny SRP functions” how do I break this cycle?

This question is important for me in growing in my technical abilities. I find I swing from end-to-end, like a pendulum, in writing code that is simultaneously DRY yet readable & efficient. And I'...
1
vote
1answer
88 views

Should I extract method to reduce duplication if the resulting method's functionality will vary based on type of collection given to it?

I am designing a treeNode class. While implementing the getPathToParentNode() and getPathFromParentNode() methods, I noticed that their functionality is essentially the same - they just operate on ...
1
vote
3answers
1k views

How to DRY refactor several similar functions?

I was assigned a refactoring. We have several modules having similar functions with some differences. My task is to extract common portions of code for DRY principle. I am a little lost how to do it....
4
votes
1answer
870 views

How does the Aggregate Root concept and the Repository Pattern solve DRY in database operations?

If I have ten classes, and they all need CRUD operations, how does an Aggregate Root and the Repository Pattern solve me having to write lots of boilerplate code (the DRY)? Take the example of a ...
5
votes
3answers
1k views

Is it poor practice to have a class implement an abstract class without adding any new fields/members/functionality?

I am writing a wrapper for a REST API and I have run into something I have never had to ask myself before. This API is for E-Commerce transactions, it has SALE and RETURN endpoints (and some other ...
1
vote
1answer
53 views

Is it worth encapsulating messages shown to a user from a repeated operation?

For example, say I have a service that kicks off some operation, such as running a cron-job. Then, it returns whether it not it was successful. The code might look something like var service = new ...
6
votes
4answers
2k views

Why aren't OOP design patterns included in the standard libraries?

I have a question similar to this other question Why aren't design patterns added to the languages constructs? Why isn't there java.util.Singleton and then we inherit it? The boilerplate code ...
1
vote
2answers
182 views

Call class method only if condition is met

Everytime I make a http request I must make sure there is internet connection. public class InternetCheck { public static boolean isOnline() { } } class Httphandler { public static ...
4
votes
2answers
133 views

One function to produce a couple or a function per item?

I have a dilemma. Let's say I have an AST that describes some grammar, for instance. I can write a function to stringify this AST back into human-readable BNF form or generate a parser from it. I can ...
4
votes
3answers
194 views

How to DRY with calls to a database to execute?

I'm writing a python app that instructs a database to perform various processing instructions on partitioned tables. The processing can take long enough that there might be a timeout, so I surround my ...
3
votes
1answer
175 views

Should I only load in the code I need if there's no performance impact for loading all of it

I have a software application. Currently at the start of each Controller it loads in only the Models it needs for that Controller. I recently tested and found that including all the models appears to ...
2
votes
1answer
149 views

Using relative units instead of px following DRY principles

I am relatively new in web development, but I am trying always to find the best way and make my code even CSS and HTML clean. So I've started exploring best practices. First of all lets start ...
1
vote
3answers
527 views

How can one think of a relational schema in terms of storing it in a NoSQL database?

Recently I've been wanting to experiment with NoSQL databases, especially document store ones. After reading, I still don't understand how one might model information that is contained in a relational ...
3
votes
1answer
68 views

WebForms, JQuery and the DRY principle

I'm working on a WebForms application that has several pages. Each page currently loads JQuery in a script tag in the head. A colleague I'm working with insists this is WET code and a violation of ...
3
votes
2answers
275 views

How to stay DRY with return values

I have a bunch of repetitive C++ code that looks like this: // Compute finalOutput if possible. Return true if successful, false otherwise // finalOutput only holds a valid value if true is returned. ...
1
vote
2answers
579 views

What did the reviewer refer to in this code review?

I sent the code for a job application and got the following review: Regarding the Project Structure: Physical separation is absent. Logical separation is present but not up to best practices. Things ...
1
vote
1answer
121 views

How to avoid repetition in docstrings?

I find that in my code, many methods in a class or a set of related classes have quite similar arguments: Arguments: dt_start (datetime): Starting date. Needs to meet complex requirements x and y ...
1
vote
3answers
365 views

How can I sell DRY? [closed]

Where I work we have around 10 VS projects in a solution which are identical in functionality (with some different different rules in a few methods) and share many exact methods. They share the same ...
1
vote
1answer
437 views

Tab management code in single-page applications acceptable violations of the DRY principle?

I have an AngularJS-based single-page app that allows the user to operate multiple items at the same time. I decided to use a multi-tab UI implemented in custom code. However, the user begin to ask ...