Lesson #100 in DLang YouTube playlist is coming -- Want to contribute what goes in?
cc
cc at nevernet.com
Thu Jun 27 16:22:53 UTC 2024
On Wednesday, 5 June 2024 at 14:37:41 UTC, Mike Shah wrote:
> 1. What's your favorite feature of DLang?
Extremely powerful metaprogramming/templating/introspection that
is also syntactically clean and aesthetic (from the end user's
perspective). "Modify code in only one place" philosophy so
updating a basic data structure, when done right, does not
require any additional changes to other areas of code such as
parsers, readers, writers, enumerators, etc. UDAs and .tupleof
make magic happen.
> 2. Why did you choose the D programming language or what first
> drew you in?
Was looking for a better, more modern language with a comfortable
migration from the C lineage or syntactic philosophy that isn't
the eternal disaster of C++. The choice at the time was D or Go,
and I'm glad I picked D.
> 3. One cool D Language trick/idiom you'd like to share.
```d
void toString(scope void delegate(const(char)[]) writer) {
writer.formattedWrite("Just because you can allocate doesn't
mean you need to.");
}
```
> 4. Why you're excited about the future of DLang
Adam's fork should hopefully encourage two parallel development
paths to keep improving and (hopefully) learn from each other. I
use D professionally and creatively, so I'm actually rather
interested in new features that aid workflow, like the recent
string interpolation, moreso than what interests the language
specialists lately, like code freezes apparently. I like new
toys and I feel confident I won't hurt myself on their sharp
edges.
> 5. A cool article/resource/favorite DConf talk/blog you'd like
> to share
DConf '22: Structured Concurrency -- Sebastiaan Koppe
https://www.youtube.com/watch?v=hJhNhIeq29U
> 6. A cool project you'd like to share (e-mail me images and
> short video clips if you like!)
Loosely inspired by above, I rolled together a simple but
flexible asynchronous RPC/proxy layer that makes use of the CRTP.
The full version is not in a state I'd want to publish, but a
slimmed down proof of concept looks like the below. Naturally
this version operates synchronously, but one can imagine the full
effect when function calls and their replies are serialized and
transmitted across a network, etc. Javascript's sync stuff works
similar to this AFAIK, but what's amazing IMO is just how
*little* D needs to be written to achieve things like this, and
it can be easily slapped on top of just about any existing class
setup. Even the completed version I wrote with network dispatch
clocks in at under a thousand lines.
Full: https://rentry.org/o628eptk
```d
class Person : Proxyable!(Person, "name", "getPerson") {
// Template args specifiy how the Proxy layer
retrieves a
// unique ID for an object, and contacts a remote
object via ID
static Person[string] allPeople;
static auto getPerson(string s){
if (auto p = s in allPeople)
return *p;
return null;
}
string name;
Person friend;
this(string str) {
this.name = str;
allPeople[name] = this;
}
@Proxy:
Person getFriend() => friend;
void bark() {
writeln(i"My name is $(name).");
}
int doubleMyInt(int x) {
return x * 2;
}
}
void main() {
{
// Server-side stuff
new Person("bob").friend = new Person("joe");
}
auto p = Proxy!Person("bob");
p.doubleMyInt(4).then((n) {
writefln("Doubled Result: %s", n);
});
p.bark();
p.getFriend().then((f) {
writeln("I'm the friend, and my name...");
f.bark();
});
}
```
More information about the Digitalmars-d
mailing list