Objective-D, reflective programming, dynamic typing

Eljay eljay at adobe.com
Sun Apr 5 07:54:42 PDT 2009


Hi Michel,

> I'm not exactly sure of what you're trying to do, but perhaps, if 
> you're on a Mac, you'd be interested in trying the D/Objective-C bridge 
> I've made.

I am on a Mac, and I am very interested in your D/Objective-C bridge.  Very cool!

Ultimately, what I would like to do, is what I vaguely envision as "Objective-D" syntax as part of D proper.  Without the preprocessor feel of the Objective portion of Objective-C.

I do not expect this feature to be in D 2.0.  It's a big feature, and D 2.0 has several big features already in the queue.

Maybe in some future D 3.0.  For sake of discussion, I'm going to call "D 3.0 (maybe) that supported Objective-C-like capabilities" Obj-D.

Here's the tricky part...

If Obj-D were link-and-interop compatible with Objective-C, that would be an impressive feat, and I would leap for joy.

But that's setting the bar high, and unnecessarily constraints Obj-D, since Obj-D would use the exact same facilities that Objective-C uses.  Seems that your D/Objective-C bridge does that, without having Objective-syntax as part of D (which I consider very important to support the idiom, rather than calling selectors directly -- syntax matters).  I consider this to be the "D is C API & C ABI friendly" equivalent for Objective-C.

If Obj-D were able to easily "toll free bridge" to-and-fro with Objective-C -- basically enabling reasonably easy Cocoa / OS X programming -- I'd be more than satisfied.

But that still means a lot of work for someone to add the toll free bridging objects.  Someone would do so, doubtlessly.  Perhaps me.  But it will be a lot of work.

If Obj-D were to have learned from Objective-C (such as it has learned from C++ and Java), and then invent a purely Obj-D better solution that was not "toll free bridge" or link-and-interop compatible with Objective-C ... I would be satisfied.  And this is my expectation, assuming Walter and Andrei see the value to support the paradigm in the core language.  Rather than "toll free bridge", we'd have a "mapping bridge", and that would also be a lot of work to interop with Cocoa / OS X.

Much as a programmer can write object-oriented programs in C, a D 2.0(alpha) programmer can write dynamic typing and reflective programming in D 2.0(alpha) right now.  But the core language does not support the paradigm, and some sort of dynamic typing / reflective programming / message architecture framework would need to be built upon the facilities that D 2.0(alpha) provides.

I've run into a few of the "under construction" or "not yet implemented" or "there be dragons here" parts of D 2.0(alpha).  That's to be expected, so I've explored other aspects of D 2.0(alpha) that appear to be more solid.

Another way to achieve the same thing is to use a scripting language (e.g., JavaScript, Lua, Python, whatever) in conjunction with D, rather than try to invent an "Objective-C-like" framework within D.  I'm just tinkering right now, and learning D 2.0, so I'm finding the exercise enjoyable.

> <http://michelf.com/projects/d-objc-bridge/>

Excellent, I'll look into it!  (Woot!  Much appreciated!)

> And if compatibility with existing Objective-C code is not desired, it 
> should be possible to reuse some parts of the bridge binding system, 
> replicate the Objective-C runtime method dispatch and get a pretty 
> decent speed out of it (2x the time of a standard virtual call would be 
> a realistic goal according to my Objective-C benchmarks).

Compatibility with Objective-C is desired.  Moreso, interoperability with Cocoa on OS X.  Eventually, interoperability with Cocoa-64 and Objective-C 2.0.

Decent speed of the messaging architecture, to me, is not important yet at this stage.  One or two orders of magnitude slower (x10 to x100) than Objective-C's messaging facilities would be acceptable -- especially considering how SmallTalk-like runtime message late-binding is used, and the heavy reliance on the delegate pattern.

I presume that if the idiom is made into a key feature of D 3.0, the performance will be brought up to par with Objective-C.  Or better.  ;-)

Sincerely,
--Eljay




More information about the Digitalmars-d mailing list