grauzone wrote:
Yigal Chripun wrote:
Static languages can have Variant/box types that'll give most of the
same functionality of dynamic languages. so, instead of instantiating
list!(int), list!(string), etc, you can get one list!(Variant)..
C# provide such a feature with a keyword instead of rellying on
templates.

It would be nice if D would be extended to provide all these things. I
guess the only reason this hasn't been done is the space overhead of
full RTTI information. (And dynamic method invocation might require a
lot of hackery to manually copy the method arguments on the stack.)

The real difference is that static languages have mostly read-only
RTTI. (Java provides a very limited capability to reload classes, IIRC)
a scripting language allows you to manipulate Types and instances at
run-time, for example you can add/remove/alter methods in a class and
affect all instances of that class, or alter a specific instance of a
class. This cannot be done in a static language.

Some static languages allow it to statically add your own methods or
variables to a foreign class. An example would be AspectJ, which, among
other things, adds this feature to Java.

from what little I know about AOP - it's done at link time, not runtime. Java does however provide very limited support for this - for example, while debugging your code, you can change an implementation of a method and reload the containing class so instances of that class *that where created after the change* will call the new implementation. this allows to make small changes while debugging without the need to re-run the program each time. But you can't do things like:

Class a = new Class;
class b = new Class;
a.getClass.addMethod(foo);
b.foo();

note that this is done at run-time, not link time.


This is still not as dynamic as in dynamic type systems, but I wonder if
you really need more?

There's something similar in current static languages: you can extend
the global data segment with global variables. Global variables don't
have to be all in a single source file. Instead, the linker takes care
of collecting global variables from object files and allocating space
for them in the data segment. A dynamic linker can do this even while a
program is running!

Thread local storage (with global __thread variables) does the same
thing per thread. Threads can be created and destroyed at runtime.
Dynamic linking is still supported, I think.

Can you explain more? I don't see how globals and threads can allow me to do the above code snippet.

Reply via email to