Linked by Thom Holwerda on Tue 2nd Jan 2007 21:39 UTC
General Development "D is a systems programming language. Its focus is on combining the power and high performance of C and C++ with the programmer productivity of modern languages like Ruby and Python. Special attention is given to the needs of quality assurance, documentation, management, portability and reliability. D is statically typed, and compiles direct to native code. It's multiparadigm: supporting imperative, object oriented, and template metaprogramming styles. It's a member of the C syntax family, and its look and feel is very close to C++'s. See this comparison of D with C, C++, C#, and Java."
Thread beginning with comment 198274
To view parent comment, click here.
To read all comments associated with this story, please click here.
RE[2]: Lack of legacy code support
by tdemj on Wed 3rd Jan 2007 18:56 UTC in reply to "RE: Lack of legacy code support"
tdemj
Member since:
2006-01-03

Why do you think you can't reuse C++ directly from D?

Because the FAQ clearly states it:

"Why doesn't D have an interface to C++ as well as C? Attempting to have D interface with C++ is nearly as complicated as writing a C++ compiler, which would destroy the goal of having D be a reasonably easy language to implement. For people with an existing C++ code base that they must work with, they are stuck with C++ (they can't move it to any other language, either)."

What you can do to reuse an existing code base is to flatten it to a C API. D is fully compatible with pure C-style interfaces. Too bad it doesn't support COFF object files, but it works with C-style DLLs.

Also, since D seems to support COM, it means a D vtable must be 100% compatible with a C++ vtable. So you can reuse Delphi and C++ classes residing in a DLL by inheritance. Your C++ code can export an interface with virtual methods only, and D can inherit from it. This is another way of interfacing, which works under the Win32 platform as long as the exported function signatures don't use C++ types (especially not std::string or std::vector).

Either way, interfacing with existing code doesn't come free. It's quite a lot of work. In my previous post I mentioned C++/CLI, because it allows the seamless mixture of ISO C++ and .NET calls in the same unit. You can call an STL function from a managed method, for example. This way I can mix a C# call with a C++ call within the same function, without any worries. To make legacy C++ code available to C#, I still have to write a small wrapper class. Only that wrapper is much easier to write than a flat C-style API, which would require double wrapping (C++ classes wrapped into C wrapped into D classes).

You mentioned WxD. That's a wrapper around wxWidgets. wxWidgets is already wrapped into a C-style API. That makes it available for virtually any language in the world, including Python. Normally it's a very painful way of interfacing, and as I said, it requires double wrapping, with C as an intermediate layer. Go to http://wxd.sourceforge.net/ and see how an intermediate wxc library was created for this purpose. So it's NOT a direct reuse of C++ classes, it ivolves major work, and can introduce major bugs. You have to pass strings as char*, vectors as T*, and so on, in that intermediate layer.

Nevertheless, I'm honestly wishing good luck to D. I like the language, and the author is an exceptionally talented person. He built airplanes in his garage, created a major C++ compiler from scratch (many don't realize what an extraordinary accomplishment it is), and a language that's better than C++ in almost every way. It's only a decade too late for me.

Edited 2007-01-03 19:02

Reply Parent Bookmark Score: 3