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

DRY, Don't Repeat Yourself, is a software engineering principle aimed at reducing redundancy and repetition of information of all kinds.

Note that questions regarding how to refactor code are better suited on CodeReview.

2196 questions
0
votes
2 answers

Calling a different method inside of another method

Somewhat new to Python but this is a question about writing functions without repeating oneself. Using openpyxl I've created a document class and a workbook (wb) with 3 sheets inside: self.sheet1 = self.wb['sheet1'] self.sheet2 =…
user3763074
  • 343
  • 5
  • 15
0
votes
1 answer

C# Refactor method to respect the DRY principle

I have a question about how to implement a method to be able to use it in other methods without repeating code and respecting the DRY principle. Let me explain better, I have more methods like this: public async Task
pampua84
  • 696
  • 10
  • 33
0
votes
3 answers

jQuery how to DRY the similar onclick event calls

I want to listen to two input change events, when one of the changes, check the checkbox and disable the element. Likewise, it needs to roll the checkbox back to the previous state when the value of input boxes back to the default values. The click…
rj487
  • 4,476
  • 6
  • 47
  • 88
0
votes
0 answers

How to make a function with event DRY?

I'm having a bit of a problem here. I'm using the same function with two series of buttons, but I have to make two seperate functions because of the event in it. const switchButtonSite = (e) => { siteBtn.forEach(button => { if(e.target ===…
MFA86
  • 185
  • 1
  • 1
  • 9
0
votes
0 answers

How to refactor following class

I am developing key-value database (https://github.com/nmmmnu/HM4) There I have code like this: enum class Command{ INFO , SAVE , RELOAD , GET , GETX , COUNT , SUM , MIN , MAX }; template
Nick
  • 9,962
  • 4
  • 42
  • 80
0
votes
0 answers

Is there way to pass a formula or algorithm from Ruby to Javascript?

I'm trying to keep my code DRY. I have two virtually identical methods for calculating the cost of certain products. The formula is $35 for the first item and $15 for every subsequent item, unless a customer has credits, then the first x items are…
Okomikeruko
  • 1,123
  • 10
  • 22
0
votes
1 answer

Suggestions to make this jQuery function more DRY / more efficient

Following previous post the this code works and does the job but I am conscious this is about as DRY as the Pacific on a wet day. I's be grateful for any suggestions that will make it more efficient. $( "#cvl_mb_services .content-switch"…
richerimage
  • 125
  • 2
  • 10
0
votes
1 answer

Javascript optimize - find ids from a list and map it to Tree

I have a tree data whose interface is defined as below: interface IData { id: string; label: string; . value: string; expanded: boolean; condition?: boolean; dataState: 'SUCCESS'; locked: boolean; enabled: boolean; parent: string; …
Veryon890
  • 330
  • 1
  • 4
  • 15
0
votes
3 answers

Mirror an object to another in java

Have two different classes: A and B. They have exactly the same field names. Suppose their definition is below: import lombok.Builder; import lombok.Data; @Data @Builder public class A { private String attriA; private String attriB; private…
laahaa
  • 327
  • 3
  • 12
0
votes
1 answer

Access different SQL Server Types such as TSql or MySql in the same method in C#

Currently I'm writing a program to access multiple 'types' of SQL servers, such as TSQL or MySQL in C#. I created a base class DBConnector that has an abstract method: public abstract class DBConnector { //some other code... protected…
Stefan
  • 25
  • 4
0
votes
2 answers

Continuation line trick to adjust Fortran I/O at compile time, with CPP directives, avoiding redundancy

Within some legacy Fortran 77 subroutines I was using the continuation mark & in position 6 and few cpp directives to adjust I/O at compile time - depending on very few parameters - to avoid redundancy. Look at a simpler example, here below: …
andreagalle
  • 620
  • 6
  • 17
0
votes
1 answer

c# apply DRY standards to multiple classes

I am working on a project at the moment with a lot of classes that inherit from a base class. This is in a test project. The base class looks like this: public class DatabaseContextContext { public DatabaseContext DatabaseContext; protected…
r3plica
  • 13,017
  • 23
  • 128
  • 290
0
votes
2 answers

Avoiding code repetition when iterating through an IShellItemArray

I'm writing a large library of functions that act on IShellItemArrays. Practically all of the functions need to access each IShellItem (and more specifically, each IShellItem2) in the array individually. So unless I'm overlooking something in the…
user13366655
0
votes
0 answers

Is there a difference between these two blocks of code, besides length?

Is there a difference between these two, besides length? Ignore the mistakes in the code please. I'm new. What I would like to know is, why should I choose one over the other. They both do the same thing in the Terminal, but I'm interested in more…
Jack
  • 1
  • 3
0
votes
1 answer

How can I DRY my code in the context below(android)

I am new to android development and using shared preferences to show ads after a number of buttons clicks. I have several buttons(Like the example below) each with a different intent. What would be the best implementation for my single logic below…
1 2 3
99
100