Possible Duplicate:
Representing dynamic typing in C
A professor at my History of Computation side-lecture went into great depth about manifestly typed or type-inferred languages and generally praised the greatness of latently typed languages (faster dev times, dynamic systems, etc…).
The same day, at an Automata Class, another prof says:
Dynamic typing makes things more complex by adding more ways to do the same thing.
I’ve been using statically typed languages most of my life : C/C++/Java – my only exposure to the other has been Shell Coding and Ren’Py.
My question is, can I write a simple program in C that implements some of the benefits of both ?
For instance, I could create Unions to accept all user driven data, like so :
typedef union {
int int_type;
char char_type;
//and so on
} dynamic;
// Var Creation :
dynamic data;
// For unknown return type
void* function(dynamic data);
I realize a Union could compromise type-safety, but that is what I’m trying to do here. What other approach could I take ? I’m just trying for a demonstration.
I tried for an answer from this question. But honestly, I could not follow the arguments closely.
I apologize if the question seems silly.
PS
Using suggestions from below, I wrote this : http://codepad.org/A9JAX8lD, which basically does nothing much dynamic, but is at least a start.
I think I see what both my professors were trying to say.
My suggestion is not to try doing dynamic typing in a statically typed language. It will most likely have sub-par performance and a very strong syntactical burden. Instead, if you only ever have experienced statically typed languages, I would strongly suggest trying out Python. It is highly dynamic and will teach you new ways of thinking.
And last but not least, there also is Cython which is a Python dialect using C as intermediate language. It can mix static typing and dynamic typing, it’s really refreshing.