D versus Objective C Comparison
Jacob Carlborg
doob at me.com
Sun Feb 1 07:42:11 PST 2009
Michel Fortin wrote:
> On 2009-01-31 20:51:57 -0500, Chris R Miller
> <lordsauronthegreat at gmail.com> said:
>
>>> If you had a smart enough dynamic linker and the signature of each
>>> function in the virtual table, you could do that in D too by creating
>>> virtual tables and updating offsets in the code accordingly while
>>> linking. (Objective-C doesn't work like that, but it has the same
>>> effect.) Alternativly, it could be done in some static initialisation
>>> phase.
>>
>> An increasingly interesting toy to study (I would think) would be
>> Categories - the ability to take an existing class and just randomly
>> tack on additional receivers. Perhaps this is exclusive to
>> Objective-C's message-receiver architecture, but it's a curious little
>> technology nonetheless.
>
> I'm sure we could add something like categories with what I'm proposing
> above. In fact, many people on this list have requested a way to write
> extensions to classes: more methods you can invoke using the dot syntax.
> Perhaps virtual tables built at runtime could allow people to write
> class extensions and still be able to override extension methods in
> subclasses.
>
It would be great if D could have categories/open classes and you could
do something like this:
class A
{
void foo () {}
}
class A
{
void bar () {}
}
void main ()
{
auto a = new A;
a.foo;
a.bar;
}
And it should of course work on classes you don't have access to the
source code.
More information about the Digitalmars-d
mailing list