Questions tagged [type-safety]
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.
24
questions
52
votes
3
answers
16k
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>. ...
27
votes
3
answers
2k
views
A Failable<T> that allows safe returning of exceptions
This was inspired by a conversation in chat, that started with the discussion of C#7.0 tuples and out parameter declarations, which led to the idea that there is no 'good1' way to return an error ...
24
votes
3
answers
1k
views
Formatted print without the need to specify type matching specifiers using _Generic
This code allows printing in C with a style similar to C++ ostream. By using _Generic() (see ...
12
votes
4
answers
3k
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 ...
7
votes
2
answers
9k
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
2
answers
450
views
Reusable storage for array of objects
My goal is to have a memory pool non-template class that is used to store arrays of objects.
The same memory pool object must be reusable for a different array (difference size, different type and/or ...
3
votes
1
answer
738
views
Type converter framework (v2)
This is the second version of my type converter framework.
The the previous one can be found here: Type creator service & framework
In this version I mostly implemented what @Dmitry Nogin ...
3
votes
1
answer
64
views
Reusable storage for array of objects V2
Here is a follow up on Reusable storage for array of objects, taking into account the provided answers.
The following code should be compliant at least with gcc, <...
29
votes
5
answers
51k
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 ...
19
votes
2
answers
1k
views
Enforcing string validity with the C# type system
One of my biggest complaints about .NET is that there's no way to guarantee a string match a certain type in the type-system.
Note
This started as more of a proof-of-concept than a real usable system,...
16
votes
3
answers
531
views
Type-safe Date class with total encapsulation
I want to teach about "encapsulation" and chose Date with Year, Month and ...
14
votes
1
answer
3k
views
C++ identity function
I've implemented an identity function (well, actually a functor struct) in C++. The goal is that every occurrence of an ...
13
votes
1
answer
2k
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 ...
13
votes
1
answer
243
views
Multi-function memoizator and multi-type container
I'm trying to write a multiple functions memoizator, which I've talked about here. The main problem is creating a container containing different and heterogenous functions.
I found a working solution,...
8
votes
3
answers
1k
views
'StrictInt' Python object class that prohibits casting numbers with non-integer components to `int`
Inspired by and created because of python3 utility: convert safely to int and driven partly by the 'refactor' in my answer.
The aforementioned question and my answer drove me to go and do a thing ...
7
votes
2
answers
450
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 ...
5
votes
2
answers
724
views
Asynchronous HTTP JSON request
For asynchronous requests, I use Alamofire.
I have created one method for requesting async data.
...
5
votes
1
answer
3k
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 ...
4
votes
1
answer
121
views
SI type safe unit calculations
I wrote a small type-rich MKS Unit system for the consistent and safe calculation of physical units in everyday use.
I realized some operators' implementations via the Barton-Nackman trick while ...
2
votes
0
answers
58
views
SI type safe unit calculations (revised)
This is the continuation of the questions raised in this thread
I did include the improvements that were mentioned but still feel like, I do more copies than I need to. Also I am unsure about the ...
2
votes
1
answer
1k
views
Login system with password reset sent to e-mail using PHP and PDO
I really like to use PDO because it's simple and easy to make a safe query, i prepared all queries and used placeholders, i think it's safe but i'm not sure at all, and I'm thinking if i used ...
2
votes
2
answers
145
views
Type creator service & framework
I needed a mechanism for creating types dynamicaly from strings and bytes etc.
I tried really hard to use the .net's TypeConverter system as it seemed to be the ...
2
votes
0
answers
45
views
Reusable storage for array of objects V4
Here is a thirdfollow up on Reusable storage for array of objects, Reusable storage for array of objects V2 and Reusable storage for array of objects V3, taking into account the provided answers.
The ...
1
vote
1
answer
46
views
Reusable storage for array of objects V3
Here is a second follow up on Reusable storage for array of objects and Reusable storage for array of objects V2, taking into account the provided answers.
The following code should be compliant at ...