class extensions

janderson askme at me.com
Fri Aug 31 08:46:57 PDT 2007


janderson wrote:
> Michael Deardeuff wrote:
>> I am very excited about the future of D. Walter's and Andrei's talk at 
>> the conference was awesome.
>>
>> However, there are still a few quirks to get out:
>> This is regarding slide 9 of the presentation.
>>
>> I noticed that most people at the conference liked the idea of 
>> extending library classes, but were not to pleased with the 
>> interchangability of ---
>> foo(a, args)
>> ---
>> and
>> ---
>> a.foo(args)
>> ---
>> like the arrays have.
>>
>> I have a suggestion: class extensions kindof like C#'s partial classes
>> ----
>> class A {...}
>> ...
>> extension class A {
>>    void foo(args) {...}
>> }
>> ...
>> a.foo(args);
>> ----
>> (maybe the syntax could be "class extension A" or "extension A"...)
>>
>> In this way class extensions are clearly marked and the syntax is 
>> consistent.
>>
>> It would be easy to add interfaces to the library class:
>>
>> extension A : Visitable {
>>    void accept(Visitor v) {...}
>> }
>>
>> Just an idea for you guys, Walter, Andrei, and the community.
>>
>> --Michael Deardeuff
>>
> 
> I'm on the camp that like the interchangeable method/function syntax 
> because it will encourage people to write better code, rather then 
> sticking everything into the class body.  It also allows you to change 
> methods into functions and visa versa without breaking the users code.
> 
> -Joel

Here's a thought.

Will this work with C code such that we could for instance expose a 
class C++ in C like form and then use it in D like a regular class, and 
visa versa?

Note of course would only applies to classes without V-Tables.



More information about the Digitalmars-d mailing list