type-safety

Feedback on iterating over type-safe enums

In response to the earlier SO question "Enumerate over an enum in C++", I came up with the following reusable solution that uses type-safe enum idiom. I'm just curious to see the community feedback on my solution. This solution makes use of a static array, which is populated using type-safe enum objects before first use. Iteration over e...

Type-safe mapping from Class<T> to Thing<T>

I want to make a map-kind of container that has the following interface: public <T> Thing<T> get(Class<T> clazz); public <T> void put(Class<T> clazz, Thing<T> thing); The interesting point is that the Ts in each Class<T> -> Thing<T> pair is the same T, but the container should be able to hold many different types of pairs. Initially I...

Make this reflection method call typesafe

class CustomerMessage { private string name; private Dictionary<MethodBase, object> changeTrackingMethods = new Dictionary<MethodBase, object>(); public int Id { get; set; } public string Name { get { return this.name; } set { this.name = value; this.PropertyChang...

TypeLoadException is Not Caught by try/catch

I am trying to re-create a TypeLoadException for demonstration purposes, so I have a ridiculously goofy library setup that looks like this: TestProject --> TheLibrary [1.0] \-> ProxyForV2 -> TheLibrary [2.0] TheLibrary version 1 has these relevant interfaces: public interface IConsistentThing { int ConsistentProperty ...

mix generic type variables to implement a type-safe map function in Java

Hi, I want to write a type-safe map method in Java that returns a Collection of the same type as the argument passed (i.e. ArrayList, LinkedList, TreeSet, etc.) but with a different generic type (that between the angled brackets), determined by the generic type of another parameter (the resulting type of the generic mapping function). ...

Benefits of .Net's AppSettingsReader vs ConfigurationManager for reading application configuration settings

Is there a substantial difference between the AppSettingsReader class and the AppSettings member of the ConfigurationManager class in .Net 3.5? I'm building out some legacy code and a previous developer used AppSettingsReader.GetValue(), whereas I am more prone to use ConfigurationManage.AppSettings.Get(). Looking at the internals, App...

Can I make the ternary operator treat my class like a bool?

I've recently been doing a huge refactoring where I was changing a lot of my code to return booleans instead of an explicit return code. To aid this refactoring I decided to lean on the compiler where possible by getting it to tell me the places where my code needed to be changed. I did this by introducing the following class (see here...

What does it mean for a language to be statically typed?

My understanding is that it means that one can potentially write a program to formally prove that a program written in a statically typed language will be free of a certain (small) subset of defects. My problem with this is as follows: Assume that we have two turing complete languages, A and B. A is presumed to be 'type safe' and 'B' i...

Type safety in Python

I've defined a Vector class which has three property variables: x, y and z. Coordinates have to be real numbers, but there's nothing to stop one from doing the following: >>> v = Vector(8, 7.3, -1) >>> v.x = "foo" >>> v.x "foo" I could implement "type safety" like this: import numbers class Vector: def __init__(self, x, y, z): ...

How to validate classes in a hierarchy in a generic type-safe way?

Hey guys, I'm stuck with what seemed to be a very simple task at the very beginning. I have a class hierarchy each class in which can define its own validation rules. Defining validation rules should be as simple as possible. Here is what is almost what is needed: class HierarchyBase { private List<Func<object, bool>> rules = new ...

How can I do type-safe Xpath queries in Java?

I'm currently using JDOM for doing some simple XML parsing, and it seems like nothing's type safe - I had a similar issue with using the built-in Java DOM parser, just with lots more API to wade through. For example, XPath.selectNodes takes an Object as its argument and returns a raw list, which just feels a little Java 1.1 Are there g...

Possible to have compiler support (type safety) for avoiding double encoding for anti-XSS during Web development?

Is it possible to have compiler support to enforce the cleanup of data (XSS encoding)? This question got me thinking about double encoding and the other times when encoding is needed. Seems like it would work great for Linq, but possibly I may need this feature in other scenarios as well. http://stackoverflow.com/questions/3774776/mic...

PHP Objects and their Functions

I am using PHP 5 now and I am exuberant to use OOP in PHP 5. I encounter a problem. I got few classes and few functions inside them. Few functions require arguments to be passed which are object of those classes I wrote myself. Arguments aren't strictly typed I noticed. Is there a way to make it strictly typed so that at compile time I c...