Objective-D, reflective programming, dynamic typing

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Fri Apr 3 09:47:33 PDT 2009


grauzone wrote:
> Andrei Alexandrescu wrote:
>> grauzone wrote:
>>> Andrei Alexandrescu wrote:
>>>> void fun(...)
>>>> {
>>>>     ... use void* _argptr and TypeInfo[] _arguments ...
>>>> }
>>>>
>>>> I'll ignore the fact that binding the arguments to magic, predefined 
>>>> names has the elegance of a fart interrupting a solemn moment. The 
>>>> larger problem is the type of _argptr.
>>>
>>> That surprises me. Your string mixin callbacks (or whatever is the 
>>> correct name for this idiom) in std.algorithm also use magic, 
>>> predefined names like "a".
>>
>> The situations are different. (The "$" in array index is also different.)
> 
> How are the situations different?

I don't have much time to explain, but the code in which a and b are 
used (which is restricted to an expression) cannot possibly define its 
own symbols called a and b. Also, user code can never define $. In 
contrast, _arguments is a valid, nonreserved D symbol that's just up for 
grabs.

>>>> No safety can be built into a function that traffics in void*, EVER. 
>>>> No matter what you do. A proverb goes "No matter how nicely you 
>>>> dress a mule, you'll still call it a mule." (It was s/mule/ass/g in 
>>>> Romanian, but ass is ambiguous in English.) So yes, it would be a 
>>>> waste of time to embellish a fundamentally deeply unsafe feature. A 
>>>> better use of time would be to improve its safe counterpart.
>>>
>>> The void* is paired with a TypeInfo. A Variant uses raw data and 
>>> TypeInfo, and manages to be reasonably safe. If you want guaranteed 
>>> safety, you must use something like Java (or SafeD vaporware).
>>
>> I don't want guaranteed safety. I want safety when lack thereof is 
>> gratuitous.
> 
> Then what's your problem with using Variant?

I don't have any problem with using Variant.


Andrei



More information about the Digitalmars-d mailing list