Questions tagged [generic-programming]

A style of programming in which algorithms are implemented abstracting from concrete data types. Usually referred to strongly typed languages this term is usually treated as creating software which is minimal in terms of data type requirements and can be instantiated for each conforming data type without changing the callee code.

This tag should be used for questions on applying generic programming techniques. Language specific features (, ) related to issues that are not directly connected with generic programming should not be marked with this tag.

Core ideas of generic programming (GP)

  1. Lifting of an algorithm stands for finding minimal requirements for a data type interface which allow to implement the algorithm. Usually this improves reusability by widening of range of conforming data types. This process reduces coupling of the software modules and reduces dependence on secondary aspects, which typically leads to cleaner code.
  2. Specification is a process of constraining data types, typically to facilitate more efficient implementation of an algorithm.
  3. Concept stands for an interface of a data type which is an object of the lifting and specification processes.
  4. Reusable, efficient code generally depends on a balance between lifting and specification.

Widely known implementations

  1. Standard Template Library (STL) which was created by Alexander Stepanov, a GP pioneer.
  2. Generics in Java and
  3. Generics in .NET

Although less known, the first relatively widely used programming language to provide direct support for generic programming was Ada 83.

1288 questions
-1
votes
5 answers

C++ - Generic programming - Type selection

The following fragment returns the next highest power of two for an (assumed unsigned) integer of type T. It does this by shifting the bits repeatedly. For all intents and purposes the unsigned type i used in the bit shifting loop is sufficiently…
Edward Grace
-2
votes
2 answers

Get Func request method Parameters in C#

I have two function which have some common functionality (i.e. to make connection with service and close connection after calling). I made a method named "InvokeService" with parameter of Func in it.How can I get parameters of request in…
Azaz ul haq
  • 53
  • 10
-2
votes
1 answer

Implement different concretions to an abstract class that implements a generic service

I have a generic interface and one generic class with generic methods to query the database. public interface IRepositoryBase { IEnumerable GetAll(Func, IncludableQueryable> include =…
asd123ea
  • 121
  • 2
  • 13
-2
votes
1 answer

How to iterate through a list of unknown type in JAVA

I have 2 lists of Generic type. List1 of type Generic_Class1 List2 of type Generic_Class2 I want to iterate through above lists in single for each loop. like, for(Generic_Class loop_variable: List1/List2){ } Is it possible to do in JAVA?
-2
votes
1 answer

Generic Stack (Cracking the coding interview)

I have some problems in understanding the implementation of a Stack class in "Cracking the coding" interview (for those who have the book it is the first page of chapter 3 "Stack and Queues"). The code looks like this: public class MyStack{ …
-2
votes
2 answers

Sort large file in Java

How do I sort a very large file containing some 10 million records (JSON records) with size around 6 GB based on keys. The solution should be memory optimised. I mean, there are ways to put the data into Collection and sort, but that consumes lot of…
Rohit Mishra
  • 281
  • 5
  • 16
-2
votes
1 answer

I want to automate general office admin tasks

I want to automate general office admin tasks at work am looking into using Python as my programming language. I am new to coding and understand basics but need guidance. I am proficient at using most me office programs and know sql but want to…
-2
votes
1 answer

Order field of object Java arraylist

I have an array list with a object fields 4. I need to know how to order the fields of my object "one by one" using generic methods that perform algorithms (isort, msort, qsort). I know the comparator interface but do not know how to check all…
jhashing
  • 1
  • 1
-2
votes
2 answers

Generic classes and its child

I have base class Entity and an enheritance class say Home , public class Home : Entity { public int CityId{get;set;} } public class Town : Entity { public int CityId {get;set} public Home CityHall {get;set;} public List
AMH
  • 6,363
  • 27
  • 84
  • 135
-2
votes
1 answer

Generic Right Shift

I have been given the following homework question : Given a set of 'n' elements and 'r', write a generic function to right shift the set of elements by 'r' position. If the elements are to moved to position greater than 'n' then wrap the shift…
Ray Penber
  • 29
  • 8
-2
votes
1 answer

Create a stack for various types using Qt

I need to simulate the stack using Qt, as elements which can be used for the int and string. I don't need your code, but i have literally no idea how to do it. I will be grateful for any tips.
Murad
  • 155
  • 2
  • 6
-2
votes
1 answer

a call to template-function - is it legal?

I have a template function (generic func to find the minimum), which look's like that: template int findmin(const T* a, int n, Func less){ //... } and a call: int smallest_matrix(const Matrix*a, int n){ return…
-2
votes
1 answer

Generic Programming in Go. Avoiding hard coded type assertion

I'm programming a generic cache mechanism and i need to set some attributes in a struct knowing only their reflect.Type, attribute name and reflect.Value to be setted in the attribute, but i can't avoid the type assertion, that makes my code not…
DLopes
  • 567
  • 2
  • 6
  • 13
-2
votes
2 answers

what does int cannot be dereferenced mean here

//Listener for the preorder button jbtPreOrder.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e){ key = Integer.parseInt(jtfKey.getText()); if (!tree.isEmpty()){ …
Harsh Joshi
  • 1
  • 1
  • 2
-2
votes
2 answers

getting instance of generic subclasses using its reference

Ignore this question I have a subclass which extends generic super class. Here it is BlueColorPainter extends ColorPainter; GreenColorPainter extends ColorPainter; RedColorPainter extends ColorPainter; ColorPainter…
Sreenivas M
  • 157
  • 3
  • 13
1 2 3
85
86