Skip to main content
Filter by
Sorted by
Tagged with
0 votes
5 answers
28 views

How can I change my function to allow finding both longest and shortest strings without repeating code?

I'm writing a program in Python to find the shortest and longest strings in an array, e.g. this is find_shortest: def find_shortest(words): N = len(words) shortest = words[0] i = 1 ...
anf's user avatar
  • 25
0 votes
0 answers
53 views

How can I group the common code within two classes that have the exact same definitions but the type of one member variable differs

I have two classes: Motor_Distance and Motor_Displacement that both contain identical code, however the type of the member variable count and the return type of the accessor convToCount is the only ...
timmy george's user avatar
0 votes
1 answer
82 views

Select City where first letter starts with a vowel [duplicate]

I'm doing some coding challenge. "Query the list of CITY names starting with vowels (i.e., a, e, i, o, or u) from STATION. Your result cannot contain duplicates." I solved the challenge with ...
user28114905's user avatar
-1 votes
1 answer
29 views

How to avoid documentation duplication in CG/HLSL?

Let's say we have few function overrides in CG/HLSL, and this functions need some big and almost the same documentation, so how to get it for each override without repeating the same text? /** * Long ...
danliukuri's user avatar
1 vote
1 answer
86 views

Diamond operator extends one or another [duplicate]

In my code I have two classes that are very similar (but still different), yet I want to map them both to a third class. I have it this way: class AToCMapper { public C from(A a) { // My ...
Adr4m's user avatar
  • 85
2 votes
4 answers
149 views

Mapping enum class to function overload

Hi there I am facing the following problem: I have a class with many member functions of a certain pattern. Each of these member functions has 3 overloads and these overloads are the same for all ...
user-1's user avatar
  • 43
0 votes
4 answers
74 views

How to avoid code duplication on a condition that repeats in many different queries

Several (20+) tables in my database define columns current_since::timestamptz and current_until::timestamptz. Each row in each of those tables follows the same rules: If current_since is null, the ...
Jan Klan's user avatar
  • 854
-1 votes
2 answers
59 views

How can I reduce duplication of logic between locals.tf files in different modules?

I have a locals.tf containing a bunch of lookup maps that translate tf vars with known/expected values and return the value (possibly with a suffix) for unknown values, e.g.: locals { Environment = ...
Sparr's user avatar
  • 7,712
-1 votes
1 answer
49 views

Can you link a partial class to several classes in C#

I'm writing a series of classes that all implement the same interface. While writing them, I've come to realise that they all use the same logic. Given the design of the interfaces, I can't think of a ...
ElectricErger's user avatar
0 votes
1 answer
47 views

How to reuse the same guidelines in differente constraint layouts in Android Studio

I am doing the user interface of an Android Studio Java app. I use guidelines to constraint the elements with the layout constraint, e.g: app:layout_constraintEnd_toStartOf="@+id/...
Javier Jordán Luque's user avatar
0 votes
0 answers
57 views

How to define abstract fromArray method for enums in Php?

I have following piece of code in several enums: public static function fromArray(array $array): array { return array_map( fn ($element) => self::from($element), $array ); } ...
user_51's user avatar
2 votes
1 answer
78 views

Remove the duplication of code which is exactly the same for two discrete types in F#

I have a discrete union WordContainer that is either a Doc of WordDocument or a Cell of WordTableCell. For the purposes of this specific function each type has the same API in terms of functions. I am ...
TimothyH 's user avatar
0 votes
0 answers
43 views

How can I put an action that applied on every exception in python? [duplicate]

I wrote something similar to the following code, and there is duplicated code (process_error) on every exception. But there are duplications. try: do_something() ... except KeyError: ...
jolim's user avatar
  • 321
0 votes
0 answers
127 views

Optimizing if case in c++ for calling member functions

HRESULT Block::SendAlarm(const std::string& variableName, USHORT value) { if (variableName == aAtt_name_Fault) builder.Alarms().Fault(value); if (variableName == aAtt_name_BATT) ...
amutamil's user avatar
-2 votes
1 answer
363 views

How to reuse code in GoLang in the absence of interfaces or function overriding?

I would like to know how GoLang handles code reuse without inheritances and function overrides. Below is an example of what I am facing now. I have a code base that handles POSTing an array of an ...
Yalda's user avatar
  • 684
0 votes
1 answer
171 views

How do I avoid duplicate code with similar classes, same methods with different property names

Here's a very basic example of what I'm talking about. We have Student, Enrollment, and Club, along with StudentEnrollment and StudentClub representing many-to-many relationships between Students->...
Workdawg's user avatar
1 vote
0 answers
105 views

Is there a way to use concise static dispatch inside a loop in Rust?

I have a for loop where the first iteration is a special case. The only difference is the type of one variable even though they both implement the same traits. I want to know if and how I can make it ...
Nic's user avatar
  • 117
1 vote
1 answer
360 views

How to share similar code between Cloud Functions?

I have multiple Cloud Functions in Google Cloud Platform that are very similar, changing only a few parameters and variable values ​​between them. Is there a way to tackle this problem, organizing ...
Henrique Branco's user avatar
0 votes
1 answer
78 views

Is it possible to make one method out of these three?

I have these three methods public static void HtmlEncodeUserDetails(ProfileEditViewModel profileEditViewModel) { HtmlEncodeUserDetailsByViewModel(profileEditViewModel); ...
Emilija Vilija Trečiokaitė's user avatar
1 vote
1 answer
69 views

Suggestion needed to remove duplicate class, without changing #define depends on that class static object

There is a duplicate class implementation in two projects, which are using C++. When i tried to merge the minor differences of both into a single class, i faced a blocker as the #define's in the ...
ShIvA SaI's user avatar
1 vote
0 answers
113 views

Is this n-ary weighted tree implementation idiomatic rust? I find it too repetitive

Context and description of the encountered problem Currently I'm learning the Rust Programming Language and last weekend I found myself implementing a generic n-Ary weighted tree data structure whose ...
JosRs's user avatar
  • 11
0 votes
2 answers
142 views

How to fix duplicate code fragment in android

I have this function to update my ImageView in my android project private fun weatherImageSetup(currentWeather: CurrentWeather) { fun setImage(imageId: Int) { viewBinding....
HaBuiDuc's user avatar
  • 115
0 votes
1 answer
110 views

Match enum item tuples that implement the same trait

I have written a CLI program using clap. In it, I have several structs and enums containing these structs for the specific sub-commands. I now ran into the issue of a certain type of code duplication ...
Richard Neumann's user avatar
0 votes
2 answers
8k views

How to solve sonarQube duplicate lines issue?

I pushed my code into GitLab. But my pipeline is giving me a sonarqube issue. In Sonarqube, I am facing a duplicate line issue. I don't know how to solve this issue. Can anyone help me understand and ...
jenish963's user avatar
0 votes
1 answer
134 views

Avoid SwiftUI code duplication for different views embedded within a NavigationView

I'm using the following code in order to display a view that works with Vision framework. The view is embedded within a NavigationView that presents a title and a button to dismiss the presented view. ...
Lorenzo B's user avatar
  • 33.4k
0 votes
1 answer
51 views

Reducing Java code-duplication when iteratively applying an operation on a list until stable

I am attempting to reduce code duplication in my java code. I am not a java expert, so I might be missing something basic. The goal is to operate on a list via several operators, foo1, foo2, ..., fooN....
Caleb's user avatar
  • 160
0 votes
2 answers
1k views

how to avoid duplicate codes in flutter?

for example I have a file (first.dart) and it has a code like this : @override Widget build(BuildContext context) { return Scaffold( body: Column( children: [ Text('one'), Text('...
behnami454's user avatar
3 votes
2 answers
4k views

Pydantic - apply validator on all fields of specific type

In my project, all pydantic models inherit from a custom "base model" called GeneralModel. This enables to configure the same behavior for the entire project in one place. Let's assume the ...
localhost's user avatar
  • 593
0 votes
1 answer
40 views

I need to duplicate one column or variable with conditionals

I'm working on some data and almost 4 variables has this characteristics: DptResidence DeathIndex -1-Not defined 0-No 54-North 1-Yes 81-South 0-No I need to ...
Sophia's user avatar
  • 1
0 votes
1 answer
97 views

Refactoring in Java: The method setCode(int) in the type Refactor is not applicable for the arguments ()

I'm trying to reduce code duplication by creating a new class (Refactor.java) to accommodate the methods that are called in two other classes (A and B). This is what I came up with so far: public ...
Westrany's user avatar
1 vote
2 answers
2k views

How to find duplicated CSS code in a folder(with several css files)?

i am looking for a solution to remove duplicated css from different css files a folder. I have found the following solution but this works in a single css file. *Here are the steps to install and find ...
user1953051's user avatar
1 vote
2 answers
96 views

How to use functional interface (perhaps) to pass comparison operator to a while loop?

I have two almost identical methods, the only difference is than one goes "left" and the second "right" from the spot in the array. Is there any way how to de-duplicate these tow ...
Jan Tibar's user avatar
3 votes
3 answers
287 views

How to avoid duplicate code with a helper-method for shared REST-operations like GET and DELETE

I have two methods methodOne (e.g. for a GET on questionaire) methodTwo (e.g. for a DELETE on questionaire) Both have almost same lines of code. IntelliJ also underlines the code and shows a warning:...
ma66ot's user avatar
  • 57
1 vote
1 answer
60 views

Is there a way to get generic constraints take in an enum in swift? Or is there a better way to reduce code?

What I want to do is somewhat complicated, pardon all the variable names. Currently I have been to doing something like enum Foo { enum Bar { case prop11 case prop12 case ...
Tiny Tim's user avatar
  • 275
0 votes
0 answers
656 views

Getting "duplicate class" error in IntelliJ Idea Community edition, preventing complete compilation of workspace

I am trying to compile my entire workspace with about 200 modules in it. Using javac compiler with extra arguments -Xmaxerrs 1000 -Xmaxwarns 1000 However, the compilation is getting stopped due to the ...
ayaan604's user avatar
0 votes
2 answers
123 views

How can I optimize my code so that I dont duplicate it

I'm trying to create a procedure that puts "-" between different dates and "0" if the is single digit, but i'm having a very hard time not duplicating my code. procedure put (...
Zeptuz's user avatar
  • 103
0 votes
1 answer
506 views

Reducing duplication in ginkgo specs/tests

I was writing tests using ginkgo framework, and wanted to reduce duplication within my tests. Suppose I have two tests, which have a exactly common middle section, but different start and end sections....
Tarun Gupta's user avatar
0 votes
1 answer
3k views

Dupclicator - Fatal error on WordPress login tests! SCRIPT FILE TEST, how to fix?

I use duplicator plugin for migration, as usually, and now I have this issue. I can't login too. It's not a hosting issue, I tried on one hosting and now try on Openserver, the issue is the same. I ...
libertarian's user avatar
1 vote
0 answers
39 views

CGo: How to avoid code duplication in switch

func GetStationPropsByPage(page string) []NameIndex { var ni []NameIndex switch page { case "station_sys_props": for _, n := range C.gStationSysProps { if n....
xrfang's user avatar
  • 2,276
-3 votes
1 answer
85 views

Two classes with duplicates [closed]

I'm new to Java and object oriented programming. I've tried to find the solution myself, but couldn't manage to solve this problem. I have two duplicated pieces of code which I need to remove. As I ...
dgr379's user avatar
  • 345
0 votes
1 answer
669 views

I'm having issues with pytest fixtures because of code duplication

I'm quite new to pytest and I've been told that fixtures help with code deduplication. While generally true, I've come to an impasse where I don't really know on how to proceed, or what I've read was ...
Sergiu Wittenberger's user avatar
3 votes
1 answer
150 views

Can chaining be abstracted in cypress?

I am writing a UI assertions test with cypress and I am seeing a lot of repeated chaining. Is there a way to abstract this out into a helper method for easier maintainability (and less code ...
Rinkala's user avatar
  • 83
0 votes
1 answer
217 views

How to generalize methods using functional Java

Can we reduce code duplication with these methods with the new java functional paradigm? I tried to pass the function as param. But one has Functional and the other BiFunctional. Unable to make it as ...
Forece85's user avatar
  • 498
1 vote
3 answers
136 views

How to optimize duplicated code between forms in C#

I have a self-made project called "Library Management", I have many forms: Book Form, Book Type Form, Author Form,... But I realized that the code in the forms is very similar (only in some ...
QuangGiap's user avatar
2 votes
1 answer
100 views

How avoid code duplication in visitor and const visitor base classes

I have 2 classes ConstVisitorBase and VisitorBase which contain some code to visit objects. for example: struct Node { enum class Type { ... }; Type type; } class ConstVisitorBase { ...
Sam Coutteau's user avatar
0 votes
0 answers
44 views

Prevent code duplication with both operator() and operator() const [duplicate]

Lets say I am implementing some 2D datastructure (for example a matrix), and I would like to use operator() for element access. The code could look something like template <std::size_t M, std::...
Cheiron's user avatar
  • 3,736
9 votes
5 answers
1k views

How to detect the amount of almost-repetition in a text file?

I am a programming teacher, and I would like to write a script that detects the amount of repetition in a C/C++/Python file. I guess I can treat any file as pure text. The script's output would be the ...
nowox's user avatar
  • 28.9k
2 votes
1 answer
810 views

In a GitHub Action, can I extract a recurring variable or condition?

I have a GitHub Action. In it I have several steps that should only be executed under certain conditions - in this case, these steps should be executed if the branch name matches a certain pattern. ...
Claus Appel's user avatar
  • 1,495
-2 votes
2 answers
145 views

Regex Replace c#

string formattedFormula = Regex.Replace("A1+A1", "(?!A1\\d+)[A1]" , "{" + 0 + "}"); I need the result as {0}+{0}. But this code replaced like this {0}{0}+{0}{0}...
Dev006's user avatar
  • 87
0 votes
2 answers
81 views

object constructed as one base class, method calculated as other base class (diamond inheritance and code redundancy)

I have a diamond inheritance scheme in C++ solved through virtual inheritance. The base class is general has two attributes and some method using them. class general { double attr1, attr2; public: ...
Rafael's user avatar
  • 129

1
2 3 4 5
15