Skip to main content
Filter by
Sorted by
Tagged with
0 votes
1 answer
52 views

Same provider class in different pages or per page provider class?

In Flutter, is it okay to use same provider class in different pages to avoid provider code duplication or will this approach have adverse consequences unseen to me? Should I instead go for one ...
rusty's user avatar
  • 490
1 vote
2 answers
59 views

What is the idiomatic way to handle code duplication in match bindings for Result? [duplicate]

I'll give some context here. The closure foo takes in a character and inserts it into a sorted vector. foo uses binary_search_by_key to insert the character into the vector at the correct index. What ...
kesarling's user avatar
  • 2,280
0 votes
5 answers
32 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
  • 43
0 votes
0 answers
60 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
126 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
34 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
105 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
  • 117
2 votes
4 answers
157 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
76 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
  • 914
-1 votes
2 answers
93 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,740
-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
57 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
72 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
87 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
  • 341

15 30 50 per page
1
2 3 4 5
49