Generic programming is one method for code reuse. It involves defining a general-purpose data or code structure that can be further specialized to work with concrete types at the location it is used.
Questions tagged [generic-programming]
26 questions
7
votes
2 answers
Writing generic code when your target is a C compiler
I need to write some algorithms for a PIC micro controller. AFAIK, the official tools support either assembler or a subset of C.
My goal is to write the algorithms in a generic and reusable way without losing any runtime or memory performance. And…

enobayram
- 181
- 1
- 5
5
votes
2 answers
Generic Sorting of Lists<>
I have several Lists<> that holds objects of different classes.
List listA;
List listB;
List listC;
//...
List listM;
The classes do not relate in any way and have nothing in common except that they might have a…

David
- 275
- 2
- 10
5
votes
1 answer
Using macros to implement a generic vector (dynamic array) in C. Is this a good idea?
So far I have only done personal projects at home. I hope to get involved in some open source project some time next year. The languages I that have been using the most are C and C++. I have used both languages for over a year and I feel like I have…

wefwefa3
- 997
- 3
- 10
- 21
4
votes
2 answers
Alternative To Generic Methods where Type is known at runtime
I've written a class that synchronizes a table between two databases using Dapper. The public and private Methods in the class are generic and the generic parameter is the POCO class that is being synchronized.
var Sync = new syncClass(localConn,…

GisMofx
- 379
- 1
- 4
- 14
4
votes
2 answers
Differences between streams and iterators in C++?
I'm working on code which will provide a generic C++ interface to relational datasets. Some of the data will be in tables in memory (e.g. std::set or std::vector), but some of it will be computed - either produced by a function computing results of…

Dennis
- 196
- 1
- 6
3
votes
3 answers
Wrapping Controller / ApiController to remove boilerplates
We are aiming to reduce code noise that would be common for all Controllers such as basic CRUD.
public interface IGenericController where T : BaseMaster
{
IEnumerable Get();
T Get(Y code);
HttpResponseMessage Post(T entity);
…

jbalintac
- 41
- 4
3
votes
1 answer
Any programming languages that support Generics exclusively and have no OOP support?
I am writing a paper on the tension between OOP and Generic programming created by Stepanov. He widely criticizes OOP and says it is "technically flawed" when compared to Generic Programming.
Now I know we have plenty of programming languages that…

Louie Bacaj
- 143
- 4
3
votes
4 answers
Are generic programming and OOP mutually exclusive?
I never did generic programming before, being more of a python guy, and generally using OOP. As I moved into generic programming, I faced some issues. I read the FAQ, but I am not satisfied. What I want to ask are the following questions (I am…

Stefano Borini
- 2,026
- 3
- 22
- 32
2
votes
3 answers
Single code fragment to perform two different operations
I want to manage music notes in a C# program, and I wrote a couple classes for that. However, I think I'm having trouble respecting the DRY principle. Either this or I'm overthinking things. Sorry if the question has already been treated somewhere…

qreon
- 339
- 4
- 13
1
vote
1 answer
Templates for generic code and code flexibility
I have a data which is a std::vector of a "small collection" of items of a given type struct Bunny {};.
I was vague about "small collection" because for now it's a collection of two of them, and so I'm just using the following alias
using Bunnies =…

Enlico
- 131
- 7
1
vote
2 answers
Adjective for function types on wether the values are received or sent
I don't know how to phrase this better, but I remember reading an article about type theory, that categorized the values being received by a function and the values being sent back from the functions.
The example was something like:
T2 function(arg…

Antoine Catton
- 179
- 5
1
vote
0 answers
Practice for modeling class - multiple container relationship
I have a class that could:
Have multiple types of containers
Have multiple types of implementations
and what I did to model so far is:
public interface ChildClass {
Container getContainer();
...
}
and one of its impl (have a total of…

Hasan Can Saral
- 172
- 1
- 10
1
vote
1 answer
Generic reactive collections of elements
In Visual Studio Color Theme Editor extension if you change some colors, some other related colors will change accordingly. They can become equal to the changed color or be more lighter/darker for example.
I wondered how can this behavior be…

saintcrawler
- 21
- 4
1
vote
1 answer
Get or infer template type from inherited member
So I have an assignment from college where I have to apply multiple metaheuristics to different problems. I thought that I should make everything as modular and reusable as possible to reuse metaheuristics with different problems with as little…

carloscb
- 21
- 4
1
vote
0 answers
Why isn't there parallel reduction in the Standard Template Library?
Alexander Stepanov stated in talks and interviews that his realization that eventually lead him to generic programming and the Standard Template Library, was from the case of the parallel reduction algorithm.
Why isn't there…

user1358
- 341
- 1
- 7