View mode: basic / threaded / horizontal-split · Log in · Help
October 23, 2006
Re: interface reference not compatible to Object?
Jari-Matti Mäkelä wrote:
> Walter Bright wrote:
>> Frank Benoit (keinfarbton) wrote:
>>> Is this the intended behaviour? If *every* object in D is a Object, then
>>> every interface reference refers to an Object also.
>>> This said, the above should compile?
>> Replace:
>>     i.toHash();
>> with:
>>     (cast(Object)i).toHash();
>> and it will work, *provided* that i is actually an instance of an
>> Object. If it is not, for example if it came from some COM DLL, the cast
>> will fail.
> 
> Is there much hope that the compiler will make the cast implicitly in
> the future releases?

An interface's vftbl doesn't have toString and others. It does however 
have some RTTI which means a (dynamic_) cast can be used to find the 
pointer to the Object class, but only if it is part of an Object.

This information is only available at run-time. It should not be 
implicit, since it might not succeed.

L.
October 23, 2006
Re: interface reference not compatible to Object?
Frank Benoit (keinfarbton) wrote:
> 
> Is this the intended behaviour? If *every* object in D is a Object, then
> every interface reference refers to an Object also. This said, the above
> should compile?

I wouldn't count on that. I for some time have been wanting D to allow 
an interface to be formed any were you can form a delegate. This would 
include structs, functions, literals and who only knowns what else. If 
you look at an interface as a collection of methods and enough data to 
give them a context, then above is not to difficult to imagine.
October 23, 2006
Re: interface reference not compatible to Object?
Lionello Lunesu wrote:
> Jari-Matti Mäkelä wrote:
>> Walter Bright wrote:
>>> Frank Benoit (keinfarbton) wrote:
>>>> Is this the intended behaviour? If *every* object in D is a Object,
>>>> then
>>>> every interface reference refers to an Object also.
>>>> This said, the above should compile?
>>> Replace:
>>>     i.toHash();
>>> with:
>>>     (cast(Object)i).toHash();
>>> and it will work, *provided* that i is actually an instance of an
>>> Object. If it is not, for example if it came from some COM DLL, the cast
>>> will fail.
>>
>> Is there much hope that the compiler will make the cast implicitly in
>> the future releases?
> 
> An interface's vftbl doesn't have toString and others. It does however
> have some RTTI which means a (dynamic_) cast can be used to find the
> pointer to the Object class, but only if it is part of an Object.
> 
> This information is only available at run-time. It should not be
> implicit, since it might not succeed.

Yeah, I know that. But from a *nix users point of view this is annoying.
As there are no COM-objects available, basically everything is an
Object. Some consider that explicit typecast is an ugly hack. Java wins
D here 10-0. If I make programs with 50+ classes/interfaces, I have to
write at least 200 of those typecasts. Still I cannot get any speed
advantage over Java since it caches the lookups.

Since D syntax does not distinguish between interfaces and classes when
implementing/extending:

interface b;
class c;
class a : b, c

versus

interface b
class c
class a implements b extends c

it becomes hard to look for correct signatures. Basically I have to
print the signatures to paper, recursively grep the source tree or
compile every now and then, fix something and try again since there are
no good IDE's for D with syntax checking. Ok, I might need to write 30%
less lines with D but it takes 400% more time to figure out those types :(
Next ›   Last »
1 2
Top | Discussion index | About this forum | D home