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.
3
votes
1answer
50 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 ...
1
vote
1answer
36 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
80 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
327 views
3
votes
1answer
31 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 ...
3
votes
1answer
32 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
99 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
33 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
1answer
111 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
784 views
Give me thy name, I'll invoke thee
This generic function invokes a property of a given object by name:
...
-2
votes
1answer
78 views
2
votes
0answers
27 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
105 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
58 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
147 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
256 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 ...
2
votes
1answer
38 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
62 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
50 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
977 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
49 views
WCF generic proxy caller
I have an ASP.NET web-client and many WCF services. I used it this way:
...
4
votes
3answers
189 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
69 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
87 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
186 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
86 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
336 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 ...
3
votes
0answers
106 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
172 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
198 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?
...
0
votes
0answers
230 views
Generic method to pass lambda expressions performed on DTO's to Entity Framework
The following are generic methods that I use to perform lambda queries on DTO objects. The main method applies the expression to entities and returns DTO objects mapped from the entities (entities ...
6
votes
1answer
143 views
Efficient generic type conversion between numeric types in F#
It's easy to write a function that adds two ints in F#:
let add x y = x + y
Actually, it's the same as:
...
6
votes
3answers
353 views
Generic getting single value from DB in C#
Few months ago I posted my code Getting a single value from the DB. I implemented suggested changes and this is how it looks like right now:
...
4
votes
1answer
60 views
Generic Constraints and new()
I have have attempted to use generics and constraints to create functions that retrieve and save data from a number of similar objects. Each of these objects describe their own properties. When I use ...
5
votes
2answers
161 views
Recursively merge dictionaries with generic types in C#
I am looking to implement a method that is capable of merging 2 dictionaries using generics. I've seen several great answers on SO already, but none handle the case of nested dictionaries. As in, what ...
-1
votes
1answer
76 views
Singly linked list with generics and comparable data [closed]
I am currently reading about the thread-safe implementation of a linked list. Although I implemented this linked list while keeping in mind the issues from the first code review (Binary Tree). I would ...
2
votes
1answer
2k views
Cached-object Store c# with Redis client for persistent storage
I have written a Cached-Object store with a Redis Client for persistent storage. The application that is going to use this is a heavy read application with the occasional write. I assume that entire ...
1
vote
1answer
117 views
System to handle the short lived async task
I'm developing an application in which there are many short-lived tasks which are run in separate threads. I've developed a generic and reusable system to handle such a requirement. The code snippet ...
4
votes
1answer
58 views
Event driven timed I/O
The following code is used to access a shield which converts settings written over I2C to Servo output.
I make use of the MRAA library since that's the default supported by my hardware.
To prevent ...
6
votes
1answer
536 views
JSON serializer using generics rather than System.Object
I recently created a custom static class in C# to encode, hopefully, any object it is given (or collection of objects), because I was, at the time, unaware of a native C# library that did the same ...
1
vote
1answer
105 views
Initializing local variable to generic interface
Below is my working code written as an exercise in wildcards in generics and Java 8 type inference. My question will be about the commented line in union() method. ...
5
votes
2answers
57 views
Getting a set of subscribers from a subscriberMap
In my Java event bus project, I have a private generic method that retrieves a Set<Subscriber<E>> from a private ...
5
votes
2answers
550 views
Generic method to split provided collection into smaller collections
First time writing a generic method here. Input a List<T> and an int value and output a ...
6
votes
1answer
106 views
Java 8 unit test for third-party data feeds
Use Case
I have a service that does processing of records from multiple third-party feeds. The steps are generally identical for each feed, but each feed is populated in a different location on an ...
10
votes
2answers
551 views
Optimize a generic foreach method that converts Datatable to my object using Reflection
I need to optimize this code block below, this method converts a Datatable object to the Object that I am passing by parameter, in another words, this serializes the object, however I have to run this ...
7
votes
4answers
388 views
Typed NSUserDefaults
I was looking around for a Swift wrapper around NSUserDefaults and found some very nice projects (see e.g. SwiftyUserDefaults). Unfortunately, it all boils down to ...
0
votes
2answers
182 views
Implementation of peak finder
I implemented this peak finder for practice. I have tested it. Everything looks pretty good to me. Please let me know if there is any improvement I can make.
Peak Finder
Let input be an ...
4
votes
0answers
309 views
Recursive flattening of Swift sequences
In Flatten to get all child controls of certain type in a UIView, methods were discussed to
recursively flatten a tree-like structure in Swift, resulting in an array
of all elements.
Motivated by ...
2
votes
1answer
75 views
Generic classes with inheritance/equals/comparison operators
I would like to greatly reduce verbosity of following code fragment.
What I'd like to do:
Reduce number of occurrences of MaterialRangedParam<Value> and ...
3
votes
1answer
691 views
Java Generics - Write a generic method to find the maximal element in the range [begin, end] of a list
I'm a Java beginner, going through the Generics Questions and Exercises in Oracle's The Java Tutorials.
Here's my solution to #8:
Write a generic method to find the maximal element in the range ...