Use this tag for reviews of code where type safety is a concern, for example code involving type conversions or casting which may result in type errors at run-time.

learn more… | top users | synonyms

1
vote
1answer
23 views

A safer way to return a generic indicator object indicating failure

I'm writing a singly-linked list that implements the List interface. I decided going in that I'd try to implement every method as an exercise; even the optional ...
2
votes
0answers
34 views

Add 5 strong types to an object as properties

This is a small object that allows you to pass an obj and a property name using its helper functions to create a typed var that won't save a value to the property if it isn't the right type. This ...
5
votes
1answer
69 views

C++ FlagSet: typesafe usage of enumeration as bitset/bitmask

Below is my attempt at providing a type-safe way to combine enumeration and bitset together. The resulting class is intended to be use as a set of flags, where each flag is a member of the ...
5
votes
0answers
44 views

Suggesting “safe enum” class for ISO C

There are quite some questions and answers about how to make enum really type-safe and I didn't find a solution that ensures both type safety and valid values. So I ...
4
votes
2answers
144 views

Asynchronous HTTP JSON request

For asynchronous requests, I use Alamofire. I have created one method for requesting async data. ...
5
votes
2answers
55 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 ...
4
votes
2answers
180 views

Portable C++98 thread class akin to std::thread

I want a homegrown version of C++11's std::thread. My motivation is to avoid manual memory management of the arguments passed to the thread function. I'm restricted ...
10
votes
1answer
195 views

Compile-time printf-style format checking

Inspired by this open ticket on Boost, this seeks to complete the work there. Given a printf-style format string and associated arguments, a static_assert is ...
4
votes
1answer
159 views

Compile-time printf format checking

Compile time checking of printf-like format strings Inspired by this open ticket on boost, this seeks to complete the work there Given a printf-style format string and associated arguments, a ...
3
votes
1answer
110 views

Proper use of type_info in relation to mapping components to a type

I'm trying to map a components type to the component value itself in a map. The following code all works properly. My main ...
2
votes
4answers
146 views

C-string appender for buffers and strings

Is this C appender safe, and reasonably optimal? ...
6
votes
1answer
59 views

Designing a Variable Set

In my application, I need to allow the user to store variables. Variables can only be of specific types, but I effectively handle all variables the same way no matter the type. I would also like to ...
6
votes
2answers
578 views

Implementing both poor-man's MVP and MVPVM framework

I'm actually building some kind of framework to promote code reuse without over-reusing it. Besides, sometimes as it occurs with generic types, one expects type parameters to be constrained for the ...
2
votes
0answers
73 views

Delegating which module's functions to use based on user input

My main concern with this code is this problem - given that this program could generate a prompt string from Bash, Zsh, Fish, etc., I would like to make this code easily extendable so people can add ...
5
votes
0answers
79 views

Encoding the problem domain of products and prices into the typesystem in F#

I'm trying to design a model for purchasing amounts of products in F#, following the ideas for designing for correctness (source). The idea is to use the type system to capture the different legal ...
3
votes
2answers
210 views

Removing asInstance[T] from scala code

I've written this scala code and I cannot work out how/if it is possible to remove the asInstance in the definition of class ...
2
votes
2answers
32 views

Enforcing Type with Boiler Plates

This is an implementation of Mat's List using by Pseudo-inheriting my Pythonic-List. Inheritance is not built into VBA, but it can be simulated by composing the inherited class and mimicking all it's ...
5
votes
2answers
844 views

Traversing and printing complex Dictionary types (Scripting.Dictionary) - Dictionary inside of a Dictionary

Based on this SO post - also reposted on vba4all.com with a few more details and explanations. Please notice there currently is no error handling whatsoever as I didn't analyse and consider any traps ...
4
votes
0answers
59 views

Existential Types and IO

In my attempts to grasp Existential Types in Haskell I decided to implement an integer-based fixed-length vector data type. I'm using ghc 7.8.3. Specifically I wanted to write a program which asks ...
2
votes
2answers
3k views

RESTEasy client that should use generics

I have written some code using RESTEasy to handle RESTful service calls and parse the response XML into relevant JAXB annotated classes. At the moment I have seperate methods for each return type: ...
6
votes
3answers
922 views

Simplifying a series of type checks and casts in a generic method

The if/else statements below are not good. How can I improve this method? ...
2
votes
1answer
113 views

Aggregating values of a path-dependent type

I have a type representing an immutable order which contains immutable order lines that belong to it. I want to use path-dependent types for this. Obviously you cannot instantiate a path-dependent ...
4
votes
2answers
247 views

Function object passing for a task scheduler

Here is my full implementation of a generic Functor-like class: ...
10
votes
1answer
70 views

Methods creating transform functionality on Collections

I have written a few simple-to-be-used methods in Java 8, and am wondering what could be improved upon those: ...
15
votes
3answers
323 views

Type-safe Date class with total encapsulation

I want to teach about "encapsulation" and chose Date with Year, Month and ...
4
votes
2answers
505 views

Pattern for storing object of varying type

I have a situation where I need to store fields of differing types of some data structures along with some similar metadata (The application takes data from one of many sources, some data possibly ...
10
votes
2answers
387 views

Nullable<T> Implementation for VB6/VBA

Because I was spoiled with C# and the .NET framework, whenever I have to work with VB6 I feel like something's missing in the language. A little while ago I implemented a ...
6
votes
2answers
262 views

Type safe program uniform manipulation in OpenGL

I've made an attempt at writing class wrappers around basic OpenGL objects to make managing them easier and more intuitive. Writing a generic one for program uniforms proved to require a little bit ...
12
votes
4answers
902 views

Type system for different representations of angle value

I want to implement a Type system for different representations of an angle value. Motivation to implement this as a type system comes from this question. Angle can be represented using the ...
3
votes
2answers
528 views

“Hell Difficulty” Haskell Fast & Hard

I'm a complete neophyte to Haskell with only a smidge of FP experience – I did some Racket programming academically and have written some semi-FP JavaScript professionally, but now I'm trying to learn ...
2
votes
1answer
417 views

Java reflection: Inject data generically and safely

I have become interested in reflection and I wrote a class to wrap an Object so that I can access its private instance fields. The code works great. I do not need to wory about the exceptions in the ...
8
votes
1answer
190 views

Embedded conditional code compaction

I'm porting some AVR code from PROGMEM/PGM_P to __flash, and I want to reduce the amount of ...
7
votes
1answer
191 views

Revisited IsTypeSafe method implementation for “type-safe” List

Following up on List<T> implementation for VB6/VBA, I'd like some thoughts about the revisited IsTypeSafe function, below. The previous version pretty much ...
19
votes
2answers
3k views

List<T> implementation for VB6/VBA

Recently I decided VB6's Collection wasn't enough for my needs, so I decided to implement something like C#'s List<T>. ...
3
votes
0answers
1k views

Event system using callback functions in C++

I am learning C++ and have been trying to create an event system for use in a small game. This will be the mechanism by which game entities communicate. I would be eternally grateful if someone with ...
3
votes
3answers
282 views

An attempt at a simple type safe python enum

There have been many posts here about enums in python, but none seem to be both type safe and simple. Here is my attempt at it. Please let me know if you see anything obviously wrong with it. ...
2
votes
1answer
132 views

Pythonic type coercion from input

My context is a very simple filter-like program that streams lines from an input file into an output file, filtering out lines the user (well, me) doesn't want. The filter is rather easy, simply ...
1
vote
3answers
196 views

Can I somehow tidy up this (overuse?) of generics?

I'm building a generic flat file reader which looks something like this. ...
3
votes
0answers
133 views

Improving General Algebraic DataType type-safe code for AA trees

As an exercise on GADTs I wrote a type-safe implementation of AA trees. I'm quite happy that the AANode data type correctly grasps the properties of the tree. Just ...
2
votes
1answer
783 views

Loading an Object from File with Type-Safety and Thread-Safe access

I'm attempting to write a bit of code that allows for easy and safe access to objects in a file. It seems to work great but I was curious if there was an easier way to do this or if Java already has ...
11
votes
2answers
12k views

Type-safe Dictionary for various types

Assume the following situation: you have an object that can store any object based on a key (basically, IDictionary<string, object>). You want to store ...