[haiku-development] Re: Why not C bindings?

  • From: Donn Cave <donn@xxxxxxxxxxx>
  • To: "haiku-development@xxxxxxxxxxxxx" <haiku-development@xxxxxxxxxxxxx>
  • Date: Sat, 6 Sep 2014 10:48:04 -0700 (PDT)

quot Ryan Leavengood,

> The only good thing I can say is that BeOS and now Haiku has generally
> used a minimal subset of C++, but that probably won't last.

It won't?  It's a good thing.

> But what would be the best in general is good C bindings which can be
> called from pretty much any language. So I definitely agree with you
> that we need it.

C++ is close to being callable in any language, if you know the mangled
member function name etc.  I'm not saying that would work, but the real
design problem is the virtual function OOP piece.  That's going to be
determined by the needs and facilities of the target language.  Is it an
OOP language at all, in which case you can probably graft onto that?
Or will you need some kind of hand-rolled OO vtable equivalent?  From
there you know what exactly the C layer's job will be.

I haven't looked at Python foreign code interfacing for well over a decade,
but back in the BeOS era, it couldn't "call" C, you had to write a C module.
Or a C++ module, didn't make any difference, and there wouldn't have been
need for or benefit in a generic C layer.  If Python has sprouted some kind
of C-only foreign function interface, let's say Smalltalk or whatever.

> Another option which might work for other languages is just to make
> the minimal bindings to communicate using ports (which might also be
> doable from the syscall interface) and just talk directly to
> app_server, input_server, the kernel, etc. In other words make your
> own Haiku API completely in that language and not use the current C++
> Kits at all. Because of Haiku's server architecture this is definitely
> doable.
> 
> Obviously a bunch of things would need to be rewritten, but the API
> could be designed in a way that made sense for each language.

That's an interesting idea, for someone with an idea about a suitable API.
I would guess orders of magnitude more work, as you'd leverage none of
the functionality and documentation of the BeOS/Haiku API, so "interesting"
partly in the sense where "may you live in interesting times" is a curse,
but sure would appeal to the purist.

> Lastly I would say that since this is an open source project if you
> want C bindings you should consider starting that project yourself :)

Yes, or at any rate it's probably futile to talk to the principal Haiku
developers about this in any near time frame.  Maybe on the haiku-os.org
forums, some skilled C++ programmer could be talked into spending a lot
of time writing a C layer that (in my opinion) no one would use.  If you
don't want to learn C++, it's up to you, but I think more in general,
anyone who has what it takes to write anything of consequence for Haiku
is going to have little trouble picking up the BeOS API subset of C++.

        Donn

Other related posts: