dynamic classes and duck typing

retard re at tard.com.invalid
Thu Dec 3 14:51:45 PST 2009


Thu, 03 Dec 2009 21:35:14 +0000, BCS wrote:

> Hello dsimcha,
> 
>> == Quote from BCS (none at anon.com)'s article
>> 
>>> Show me ONE thing that can be done using run time meta programming
>>> that can't
>>> be done as well or better with run time, non-dynamic, non-meta and/or
>>> compile
>>> time meta. Unless I'm totally clueless as to what people are talking
>>> about
>>> when they say runtime meta, I don't think you will be able to.
>>> Anything that
>>> amounts to making the syntax look nicer can be done as compile time
>>> meta
>>> and anything else can be done with data structure walking and
>>> interpretation.
>>> All of that is available in non dynamic languages. I guess I should
>>> concede the eval function but if you don't like CTFE+mixin...
>> Oh come on.  I'm as much a fan of D metaprogramming as anyone, but even
>> I admit that there are certain things that static languages just suck
>> at.  One day I got really addicted to std.algorithm and decided I
>> wanted similar functionality for text filters from a command line, so I
>> wrote map, filter and count scripts that take predicates specified at
>> the command line.
>> 
>> filter.py:
>> 
>> import sys
>> 
>> pred = eval('lambda line: ' + sys.argv[2]) for line in
>> open(sys.argv[1]):
>> if pred(line) :
>> print line.strip()
>> Usage:
>> filter.py foo.txt "float( line.split()[1]) < 5.0" Metaprogramming isn't
>> very rigorously defined, but this has to qualify.  Try writing
>> something similar in D.
>> 
>> 
> Yup, eval is the one thing that dynamic *really* has over static.

You can even send the runtime generated string via network to some other 
process that runs on a completely different cpu architecture and still 
compute the result. You can do this with D too, but you need to write the 
interpreter or JIT yourself. Dynamic languages provide this as a built-in 
feature. Guess why D or C++ isn't used much in client side web site 
code :)



More information about the Digitalmars-d mailing list