← Back to team overview

coapp-developers team mailing list archive

Re: Code?

 

On 5/17/2010 7:43 PM, Trevor Dennis wrote:


On Mon, May 17, 2010 at 5:38 PM, Elizabeth M Smith
<emsmith@xxxxxxxxxxxxxxxxxxxxxxx
<mailto:emsmith@xxxxxxxxxxxxxxxxxxxxxxx>> wrote:

    On 5/17/2010 7:36 PM, Olaf van der Spek wrote:

        On Tue, May 18, 2010 at 1:23 AM, Elizabeth M Smith
        <emsmith@xxxxxxxxxxxxxxxxxxxxxxx
        <mailto:emsmith@xxxxxxxxxxxxxxxxxxxxxxx>>  wrote:

            As we discussed during the summit and is mentioned on the wiki:

        Ah, found it.


            Few dependencies
            Fast
            Small
            Binding facilities for most high level languages are common

            The ability to tie a C library into anything and everything
            is the biggest
            reason to use C over C++, using and binding to C++ libraries
            (especially in
            most languages - they tend to be written in C) is a real
            headache - actually
            beyond a headache, most times it's just a recipe for failure.

        C++ can do C bindings as well, can't it? Our bindings should
        certainly be C.
        Doesn't C++ share the other advantages?

        Olaf

    What?  I mean binding coapp to other higher level languages
    primarily written in C.  Perl, Python, PHP, Lua, D etc.

    and if we write it in C - yes a C++ binding would be easy as well.

    Thanks,
    Elizabeth Smith


In case Olaf means writing the library in C++ itself instead of C, only
functions defined outside of a class can
be defined with a C binding.  As soon as it's in a class it must use C++
bindings and all the name
mangling takes effect.  Once that happens, connecting to the classes
from the other languages is
almost impossible.

I've seen people try to to create bindings to a C++ library and it
usually involves writing a middle C layer between the
other apps and the C++ library.  No point in doing that if we can just
write it in C in the first place.

Hrm. I'm with Olaf on this one. I've had fantastic success with minimalistic C++ APIs, very clean C exports, and then using FFI (i.e. ctypes in Python, Inline:: in Perl) in dynamic languages for binding.

And I've even got an example online:
	http://blogs.onresolve.com/?p=48

Scroll down a bit and you'll hit a section called 'Interfacing to C libraries (.dll/.so) using ctypes and decorators'. Using that approach, I had a product.dll of <25k (forgot the exact size), and I could call into it from Python, Perl and NSIS, without any reliance on SWIG or having to write CPython/Perl bridge code in C.

I'm perplexed why anyone would want to forgo the advantages of C++ for C; I can make my C++ DLLs just as small as C ones. And, like, what if I want a linked list, or a hash, or a set, are we planning on writing all of those from scratch? Even string handling alone seems like a huge win.

...

Tried to resist getting involved in this one for as long as I could ;-)

	Trent.










Follow ups

References