Generic programming is a style of computer programming in which algorithms are written in terms of to-be-specified-later types that are then instantiated when needed for specific types provided as parameters.

learn more… | top users | synonyms

0
votes
0answers
14 views

Unification with sequence variables and flexible arity functions

Today I wrote an implementation of the unification algorithm found in Temur Kutsia's 2002 paper. I didn't just do this for fun, it's related to other research I'm doing. I'm feeling more confident in ...
1
vote
2answers
88 views

Intersect two ranges in Swift

Can you think of a reason the following extension should not be used in production, or a better way of implementing it: ...
2
votes
0answers
42 views

Generic Unrolled Linked List with IList<T> interface implementation

I was inspired by the Phillip Trelford "Beyond Lists" presentation published on InfoQ. So, I decided to make it simple, yet still capable to act as IList<T>. ...
1
vote
1answer
47 views

Simple type-safe and thread-safe Rust event system

I'm creating a relatively simple type-safe and thread-safe Rust event system. It is to be used with and within an IRC library I'm making, but should work just fine for other use-cases. It needs to be ...
5
votes
2answers
87 views

Indexed Property implementation

I have a class that encapsulates a PowerShell Runspace object which, among many other things, has methods for getting and setting variables in the session state. ...
0
votes
1answer
59 views

Using T type parameter to clone a collection

I want to clone a collection with the following method and I want to know if it can be optimized ...
3
votes
1answer
92 views

Fixed-length Sequences in Swift 2.2

The following is an implementation of fixed-length sequences that makes very exotic (and hopefully fun) use of Swift 2.2 types. The question is what exactly is the cost of having the type checker ...
3
votes
0answers
98 views

A general iterator to replace “non-standard” C-style for loops

Since the deprecation of C-style for loops in Swift 2.2 (and the removal in Swift 3), several questions about the possible replacements were asked on Stack Overflow. In most cases, a ...
5
votes
2answers
85 views

A more generic `DelegateCommand`

In an effort to create ever-improving code, I've written a DelegateCommand that takes a generic type parameter to be acted upon. It's pretty trivial, so it should ...
2
votes
3answers
373 views

Generic methods to find the maximal element in part of a list

This is the question from Oracle docs: Write a generic method to find the maximal element in the range [begin, end) of a list. I had my implementation like this: ...
1
vote
2answers
95 views

Fixed-length Stack in Java

I implemented a fixed-length stack in Java for use in my fractal generator program, an RPN calculator and my esolang interpreter. This is a generic stack, and goes over and above the call of duty in ...
3
votes
2answers
68 views

Custom key class for .NET 3.5 framework

I use .NET 3.5 framework, so no tuples. I have many use cases where I have to create a custom key for a dictionary. How can I make this better? ...
5
votes
1answer
67 views

Object factory from interface types

I have a library that defines a bunch of ISprite interfaces, like IPieceSprite and ...
2
votes
1answer
88 views

Java Tree Implementation

I wrote a simple tree data type in Java consisting of nodes which are themselves trees, and where each tree has its own list of children (not a binary tree). I plan on eventually using it in a minimax ...
1
vote
1answer
39 views

Single Flag Only Enum (RestrictedEnum<T>)

This class simply allows you to use an enum while only allowing you to set a single flag. If multiple flags are set they will be rejected--unless the total of the combined flags is the same value of ...
4
votes
1answer
26 views

Matasano cryptopals: Conversion to base 64 (with generic types)

My main interest is in how I have handled the generics and if it's idiomatic. I want the user to be able to specify what kind of integer type they would like to use for the encoding (u8, u16, u32, ...
2
votes
1answer
65 views

Optimize OrderBy Generic Method

Here is my OrderBy method which includes concatenated column names. Can this be achieved more efficiently? ...
1
vote
0answers
42 views

Generic implementation of mutable binary heap

std::priority_queue does not support dynamically updating element priorities. This class template extends it by allowing updating priorities of elements in the ...
1
vote
1answer
46 views

Generic implementation of SiftUp/Down operations on binary heap

Binary heap construction and maintenance boil down to the two basic operations: sift up and sift down. Following are generic template implementations of the two operations. Any comments are welcome. ...
1
vote
1answer
61 views

Templated linked list in Java

I recently reviewed some data structure concepts, so I implemented my own templated linked list. I am very interested about the code efficient and performance. ...
3
votes
1answer
73 views

Creating a lightweight strongly-typed parameter infrastructure

I'm looking for some feedback on some code, designed to allow me to strongly-type parameters, which get passed to functions. I'm only really looking for comments on making my parameters more strongly ...
2
votes
1answer
96 views

A Dynamic CSV Serializer

I made a dynamic CSV serializer as a learning challenge a while back, I'm hoping to get my code picked apart so I can learn what I can do better. This is a bit long, so I wouldn't expect anyone to ...
4
votes
2answers
88 views

Dictionary lookup of non-nullable struct into nullable destination

I've got an IDictionary<SomeT, DateTime> that does not always contain the desired key-value pair. For that reason, a target method expects a ...
12
votes
2answers
486 views

Extension method to list enum values

I have the following enum extension method: ...
3
votes
1answer
45 views

Generic Object Editing Classes with Controller, ViewModelProvider and DBUpdater

I am beginning to use generics and would like feedback on the following set of classes that will serve as the basis for an app that contains a large number of basic CRUD-y entities. I have used ...
2
votes
1answer
55 views

Ignore nil values and unwrap optionals returning the value as the wrapped type

My primary concern is that this has been written as a global function. I think it would be better if this was a function of the SignalProducer class but I am not ...
11
votes
3answers
165 views

Poor man's lazy evaluation in Java 8

I have an class that cheaply imitates a lazy evaluation scheme. The class is for representing a file and additionally providing meta data on the file. Some of the meta-data can be expensive to ...
4
votes
0answers
40 views

Heap update generic algorithms

In the standard library, there are no algorithms for element updates. This makes it unsuitable as a queue for a Dijkstra's algorithm, for example. Thus I implemented generic heap update functions with ...
5
votes
2answers
489 views

Type to byte array conversion in Swift

I need the byte representation of a given type, especially double, float, int8, etc. ...
11
votes
3answers
796 views

Give me thy name, I'll invoke thee

This generic function invokes a property of a given object by name: ...
-3
votes
1answer
81 views

How to use generic [closed]

I have function that builds different types of boxes. ...
2
votes
0answers
49 views

Multi class-type Object pool based on Libgdx Pool

I've done some code so you can obtain Object of any Class from Pool, take a look at it, is it safe? At least it works. MultiPool class has method obtain with Class param, so can know from which ...
5
votes
3answers
115 views

EventList<T> a generic list implementation that raises events when items are added and removed

I created this class for a project when I wanted to have List<T> properties on a class and also listen for items being added and removed. I looked at using ...
1
vote
0answers
66 views

Parsing JSON with generics

I get back two dictionaries, I need to parse through them and put in an array two objects. I think I did a very poor job and I have a feeling there is a better way to make the code more compact and ...
3
votes
2answers
162 views

Mutating Objects: Mutable<T> class

Recently I felt the need to write a Mutable<T> class so that I can pass immutable objects through methods, whose value can then be changed. Some examples of ...
5
votes
1answer
277 views

Generic method for obtaining enum items in an ushort object

The idea is to perform a bit-wise scan of an ushort provided to find any and all matches within an enum collection. The code I ...
1
vote
1answer
45 views

Dynamic CSV Formatter

I made a dynamic CSV formatter as a personal challenge after having to hardcode a behavior to convert some data to CSV earlier. You input any List that contains supported types as properties (all ...
0
votes
1answer
104 views

Fixed Point Number to String

I recently learned about using fixed point arithmetic on embedded systems without floating point hardware, so I decided to code it. I tried to write in good style, but emphasized speed over style. ...
1
vote
0answers
55 views

Better way to deep copy than this? How can I make it generic by `Collection` type?

Could I make this method for deep copy generic to the Collection type? That method is so simple and I can't imagine ever needing to change it, so maybe I should ...
8
votes
3answers
1k views

Simple generic double buffer pattern

I wrote a small generic implementation of a simple generic double buffer pattern, and I was wondering if it's actually thread safe or can be improved in any way. Note: The specific part that I'm ...
-1
votes
1answer
85 views

WCF generic proxy caller

I have an ASP.NET web-client and many WCF services. I used it this way: ...
5
votes
3answers
373 views

Generic toString() for JPA base entity class

In a Java/JPA project I usually define a base class (on which I put the id). The goal is to implement an generic toString() on this base class (named BaseEntity) from which all other entities inherit. ...
3
votes
2answers
85 views

IEnumerable extension method that ingests SqlCommand and returns query results

The following ingests a preexisting SqlCommand and returns the values. A couple caveats right now. 1 ) Type properties must be named identical to the SQL column ...
3
votes
2answers
90 views

Related classes around generic types

I'm wondering if this code can be simplified. I'm less than thrilled about the fact that I repeat the Draw method in both CatModel and DogModel. For that matter, I'm not real happy that that method is ...
5
votes
1answer
196 views

Early Binding with Generics

I have a class which takes the method address and arguments, and executes it later when told to do so. ...
1
vote
2answers
100 views

Implementing a generic class and choosing a collection based on a type

In this topic here I have aksed for help to sort out an error while creating a generic class whose method can return a different collection given a type. I received the answer and working solution but ...
8
votes
1answer
420 views

Generic domain independent Monte Carlo Tree Search methods library

I've written this small generic library for the purpose of my Bachelor's thesis. It's fully functional and unit tested and I want to get as many opinions as possible regarding overall code quality ...
11
votes
1answer
241 views

OOP paradigm implementation of a Dictionary data model

Here is the implementation of interface Dictionary using chained hash table class HashTableChained. Despite item 22* saying ...
4
votes
2answers
253 views

App settings helper

The helper should be able to set a default value if the value can't be fetched with the provided key. There is also a bool that will throw an error if the key value or the default value could not be ...
4
votes
1answer
406 views

Sorting a linked list using mergesort

This sorts a linked list using mergegort. Can you please critique my code and provide your thoughts on where I should improve my code? ...