typechecking

Is there a way to check if a variable is a Date in JavaScript?

I was wondering if there is any way to check if an object is specifically a Date in JavaScript. isType returns object for Date, which isn't enough for this scenario. Any ideas? Thanks! ...

Check if Ruby object is a Boolean

Can't seem to find how to check if an object is a boolean easily. Is there something like this in Ruby? true.is_a?(Boolean) false.is_a?(Boolean) Right now I'm doing this and would like to shorten it: some_var = rand(1) == 1 ? true : false (some_var.is_a?(TrueClass) || some_var.is_a?(FalseClass)) ...

How to get printf style compile-time warnings or errors

I would like to write a routine like printf, not functionally-wise, but rather I'd like the routine to have the same time compile check characteristics as printf. For example if i have: { int i; std::string s; printf("%d %d",i); printf("%d",s.c_str()); } The compiler complains like so: 1 cc1plus: warnings being treated a...

Is there a good way to force type incompatibility in C?

For purposes of type checking I would like to define a function on the lines of void myfunc(type1 a, type2 b) { ... } where type1 and type2 are both typedefed to uint8_t. So far so good, but for sanity and checking purposes (think DbC) I would like to prevent the function being called with a type2 value for the first parameter or a t...

Java insuring that an object passed to a method extends a given class.

What would be the best way to check in an object being passed into a method extended a given class? Currently i have a method that takes a ByteBuffer of data to send and a 'player' class that i wrote, and queues the data up on the IO server to be sent to the client: public void send(ButeBuffer toSend, Player player) { // prep the byt...

Better type checking on match in Scala

scala> class A defined class A scala> class B defined class B scala> val a: A = new A a: A = A@551510e8 scala> a match { | case _: B => println("unlikely") | case _ => println("no match") | } no match In the example above shouldn't the compiler tell me that one of the cases can never match? A slightly more complicated...

Compare symbolic constant, enumeration, constant variable

symbolic constant- no type checking->the value is just substituted enumeration- more type safe than symbolic constant constant variables- most type safe Anything else that can be added here? Any difference in terms of space occupied by these? ...

Is this a good reason to check types in Python?

I know that checking types in Python is bad and you should probably never do it. But I can't seem to find the disadvantage to this. class O(object): def __init__(self, name): '''Can only be called in derived classes.''' if type(self) is O: message = "%(class)s cannot be instantiated, it must be ...

Design choices to remove if-is statements

Hi, Say i have a class hierarchy of domain objects with one base class and a couple of child classes, one level. Let say I have a list of those objects (list of the base class) and I want to apply some logic to the classes that I feel don't really belong to the classes (eg. design/UI specific code). What are my alternatives ? If-is ...

Is Type Checking a Code Smell in this code?

I have an interface "IPartyCountService" that counts number of customers and number of suppliers. The implementation class "PartyCountService" makes use of type checking to check whether the party is a Customer or a Supplier. My question is: does the implementation class PartyCountService's use of type checking give out code smell? Ple...

How to see if a type implements an interface in VB.Net?

I need to know if a Type implements an interface. Dim asmRule As System.Reflection.Assembly = System.Reflection.Assembly.LoadFrom(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Rule.dll")) For Each typeAsm As System.Type In asmRule.GetTypes If TypeOf typeAsm Is Rule.IRule Then 'that does always return fa...