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

DRY a large chunk of common code with two vastly different uses

I have a 'widget' that comprises an html/css block of code. It is a type of data layout, which I call the 'stack'. The stack has bits of .erb (Ruby on Rails) embedded in it, which enters the data for each user. I need to include this stack in…
sscirrus
  • 55,407
  • 41
  • 135
  • 228
0
votes
2 answers

Any ways to swap variables within if-statement better than this?

I'm writing a small C# console app, and I was wondering if there are ways to improve this part of code (particullary how to make it comply with the principle "Don't repeat yourself"). My app works fine with this construction too, but I don't like…
0
votes
3 answers

How to refactoring similar but not identical methods where one method extends the functionality of the other? C#

I have two methods which are very similar apart form the fact that the second method partially extends the functionality of the first method. For example the methods are below: private void ExtendTable(FileInfo file, string columnToCopy, string…
user12669123
0
votes
3 answers

How to create a generic method that works on lists of objects as long as they have the same getter methods

class County{ private LocalDate date; private String county; private String district; private String region; private Integer cases; // getters and setters and constructor } class District{ private LocalDate date; private…
Jac Frall
  • 403
  • 7
  • 15
0
votes
2 answers

How to abstract over two similar functions

I have the following data definition about a football game: Game = namedtuple('Game', ['Date', 'Home', 'Away', 'HomeShots', 'AwayShots', 'HomeBT', 'AwayBT', 'HomeCrosses', 'AwayCrosses', …
0
votes
1 answer

How to write a loop function or mixin with variables in less.js for DRY

Is there any efficient way to write this code with less.js: I've got already 3 variables colors : @vert, @violet and @orange li { &:nth-child(1) { background: @vert; &:hover, &.open { >.dropdown-menu li { …
echayotte
  • 1
  • 3
0
votes
1 answer

Best way to structure reusable code using Node.JS, EJS, and front end JS?

Evidently the 'Software Engineering' exchange was the wrong place to ask this: 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…
R Greenstreet
  • 719
  • 6
  • 21
0
votes
2 answers

Create a DRY function for multiple enums (enum subclassing?)

I have multiple enums which will all share an identical function. Is there a way to write this function once and have it present in all specified enums? Here is an example: enum CustomerTypes: Int, CaseIterable { case NewCustomer = 0 case…
Sam
  • 956
  • 6
  • 12
0
votes
1 answer

How to retrieve a polymorphic model from a single table in django - or how to implement polymorphic behaviour in django

Can I read polymorphic models from a single database table, with their behaviour depending on a (boolean) field of the model? In one of my models the behaviour is slightly different if the instance is 'forward' vs. 'backward' or 'left' vs. 'right'.…
jammon
  • 3,404
  • 3
  • 20
  • 29
0
votes
1 answer

Is the UML architecture clean and specific enough to be coded in java

I've learned the UML recently and I am trying to build a MonsterDuel system. However, there are a lot of classes in this project, and I am confused about the abstract class and its usage. Now, I have created: Abstract class Players, and its…
Woden
  • 1,054
  • 2
  • 13
  • 26
0
votes
2 answers

How to parse multiple Json files while keeping code DRY in Typescript?

My app is reading in multiple Json files in Typescript populate select boxes, but I want to avoid wet (write everything twice) code and keep things dry (don't repeat yourself). I originally had unique functions for each json file, as they each have…
MARS
  • 499
  • 1
  • 9
  • 25
0
votes
1 answer

DRY with Props in React

We have a component. Let's call it . It is being used in a dozen different files. We wanted to change the styling on this component. Fortunately, the component exposes a property stylingProps. So, we wrote the following in each of the…
ddastrodd
  • 710
  • 1
  • 10
  • 22
0
votes
1 answer

Get Class By String Name In Android To Avoid Repeating Myself

So in my code, I'm getting a list of strings, which correspond to movie genres in an enum. I'm then getting a metadata file, and going through each of those genres, seeing if the date the server updated that genre is newer than the date I retrieved…
Paxana Non Grata
  • 379
  • 1
  • 7
  • 23
0
votes
2 answers

Is there anyway I can set a variable as a range of numbers and include that in a function? (javascript)

onEvent("pb" + 1, "click", function() { console.log(("pb" + 1) + " was clicked!"); }); onEvent("pb" + 2, "click", function() { console.log(("pb" + 2) + " was clicked!"); }); onEvent("pb" + 3, "click", function() { console.log(("pb" + 3) + " was…
Jacobnarg
  • 11
  • 2
0
votes
2 answers

DRY - Typescript. How can I use DRY principles to avoid duplication of these 2 getters

I know that below two getters are duplicates and could be consolidated and written in a better way. Could any one please help me come up with a way to consolidate these:- isEqual here is a lodash library to compare two objects. state in here is an…
Veryon890
  • 330
  • 1
  • 4
  • 15
1 2 3
99
100