D vs C++ classes?
Ola Fosheim Grøstad
ola.fosheim.grostad at gmail.com
Wed Jun 30 12:22:07 UTC 2021
On Wednesday, 30 June 2021 at 10:38:36 UTC, Alexandru Ermicioi
wrote:
> On Wednesday, 30 June 2021 at 09:53:31 UTC, Ola Fosheim Grøstad
> wrote:
> If you open object.d and check for TypeInfo symbols you'll
> notice that they are final classes. We should replace them with
> a set of interfaces (with nice names without uncompliant
> underscores by code style standards), and then let d compiler
> generate an implementation for each class it has compiled.
Do you mean using a function call to obtain specific type info?
> If you want full 100% interop, just use c++. There is bound to
> be shortcomings in interoperability, and imho we should not
> sacrifice the language, just for that. If this will be the
> future orientation for D I don't see the point of it having
> letter D, let's just rename it to C++++
Runtime compatibility does not equate compile time limitations,
so it isn't really all that limiting given the current D
semantics. The difference between D and C++ on the compile time
level isn't really touched.
> 1. My suggestion of allowing to express multiple inheritance,
> was for c++ class declarations only, i.e. class header files
> only.
> 2. Making them compatible with C++ abi doesn't imply that they
> are c++ classes, and hence should support all c++ features.
> They are still D classes or a subset of them that can be called
> by c++ code.
You need to be able to specialize C++ classes in order to have
full C++ library interop. So it is a given requirement that you
need to be able to declare/define/instantiate extensions of C++
classes in D, in order to have basic C++ interop.
> Let's not conflate two distinct domain objects into one. There
> is a class that is written in D, and there is one written in
> C++, they are not the same thing.
You need to be able to extend the one in C++ from D in order to
integrate, so it basically is the same thing.
Most modern C++ libraries are also heavily templated so to have
basic interop you actually need to translate D code to C++.
That is, if C++ interop is a goal. Most people don't want 50%
interop they expect close to 99% interop. If only 50% is the
goal, then maybe just stick to C interop and forget about C++,
most people don't care for 50% anyway.
> Let's also clarify what full interoperability means. Per my
> understanding, this means that I can use all of libs written in
> c++, and then I can expose my D code to the c++ libs and allow
> them use it, but it does not mean, that I need to follow the
> c++ rules for the oop, or any other feature, otherwise, why not
> replace D lambdas, with std::function from c++? We need full
> interoperability...
std::function is just a buffer, but yes, D does need something
comparable although in C++ std::function is a last resort, you
would typically use a template instead.
More information about the Digitalmars-d
mailing list