article comparing Rust and Zig, many points relevant to D
Adam D. Ruppe
destructionator at gmail.com
Thu Mar 11 01:42:45 UTC 2021
On Wednesday, 10 March 2021 at 21:51:43 UTC, mw wrote:
> What is the exact usage of this feature?
http://dpldocs.info/experimental-docs/source/arsd.jni.d.html#L1358
That _jmethodID is unique for each method added. So when you
follow the example code:
http://dpldocs.info/experimental-docs/arsd.jni.html
and have like
@Export void hi(string name) {
import std.stdio;
writefln("hello from D, %s", name);
}
// D can also access Java methods
@Import void printMember();
Then hi and printMember both get their own private copy of the
id. No conflict regardless of how many methods you mixin.
Notice too how these mixin static constructors too, which are all
combined per language rules, allowing me to actually concatenate
the lists at startup for a one-go load of metadata at runtime.
http://dpldocs.info/experimental-docs/source/arsd.jni.d.html#L1790
For the other side, adrdox uses that:
https://github.com/adamdruppe/adrdox/blob/master/doc2.d#L3169
That's a mixin template with semi-specialized implementations of
the abstract interface.
But there's also cases like here:
https://github.com/adamdruppe/adrdox/blob/master/doc2.d#L3028
That override the mixed in override, letting you accept the
default implementations in some places, and selectively override
them for other methods, without having to create another child
class to do it.
Now take a look at this line:
https://github.com/adamdruppe/adrdox/blob/master/doc2.d#L3158
Notice the explicit usage of `this` there. Without it, it would
use the local name inside the mixin template and NOT respect the
override; this is good when you want to use a private member like
in the jni example. But with it, it looks up one level above
which means the user can easily override it and then it respects
this, similar to a virtual vs static lookup in oop (which itself
can get a bit nuts if you use the curiously-recurring template
pattern, which I do here for reflection of a child class inside
the base class
http://dpldocs.info/experimental-docs/source/arsd.cgi.d.html#L8288 - the mixin template version is kinda the same idea.)
More information about the Digitalmars-d
mailing list