How D addresses the problem of Extending and/or Embedding other languages ?

Brost via Digitalmars-d digitalmars-d at puremagic.com
Sun Aug 24 23:18:30 PDT 2014


Hi,

any language that I know has its own features, sometimes is
"marketing", sometimes are really useful features, useful
algorithms and useful data structures .

Big problems arise when given an application written in the X
language, I want to plug in an Y scripting language, or a
language that is there to offer some level of interaction with
the end user.

In this scenario you tipically end up wiring everything into C
code, and use C as a bridge because both X and Y do not really
support anything other than C .

And yes there are libraries that sometimes help, but libraries
need maintenance too and libraries usually don't give strong
invariances like a good language usually does .

For example when you start from a C++ application, and you want
to expose an std::vector to your Y language, your only real
option with something like Python or Lua is to write C code that
will use a pointer to the chunk of memory where the meat of the
vector is, that contiguos portion of memory where things are
stored, and pass the size of the vector as a second argument too
because C doesn't even know what a std::vector is .

Et voilĂ , you basically have lost years and years of evolution in
language design, memory safety, type safety and all the other
good things, just to let someone else play with your std::vector
which no one know what it is except C++ itself .

This problem also makes things a lot more complicated with
concurrency and code with a complex behaviour; also I said
before, this entire concept is based on some basic invariances,
in the case of the vector the invariance is about having a
contiguos chunk of memory allocated, the same thing wouldn't be
possible with the cells of the array scattered everywhere; this
is for saying that with this way of doing "extensions" for my
applications I can't just use any library, I also need to check
things out everytime, see how they internally work, if they are
suitable and with an appropriate behaviour for this "C bridge"
that limits my original language, and by that time I can probably
write that Z library all by myself.

The only exception to the rule that I know is V8, which tries to
expose itself with C++ based APIs since it's being written in C++
in the first place, but when it comes to languages, compiled
languages, the entire Zoo of languages all point to the same
target: C .

Is D different in this regard ?


More information about the Digitalmars-d mailing list