Which language futures make D overcompicated?
rumbu
rumbu at rumbu.ro
Fri Feb 9 21:58:26 UTC 2018
On Friday, 9 February 2018 at 16:35:47 UTC, Seb wrote:
>> On Friday, 9 February 2018 at 15:06:49 UTC, rumbu wrote:
>
> All understood, but just to get your mind set better, I would
> have two quick follow-up questions if you don't mind.
>
> On Friday, 9 February 2018 at 15:06:49 UTC, rumbu wrote:
>>rough C# translation:
>>
>> async void spawnedFunc()
>> {
>> int i = await receive();
>> }
>
> OK, but that's because Phobos has no eventloop.
> With Vibe.d it looks like this:
>
>
> ```d
> auto val = async({
> return 32;
> }).getResult;
> ```
>
> Is this really so different or what exactly do you miss from
> the language?
>
>> C#:
>>
>> IEnumerable<int> Fibonacci(int limit)
>> {
>> int a = 1, b = 1;
>> while (a < limit)
>> {
>> yield return a; //syntactic sugar
>> var t = a;
>> a = b;
>> b = t + b;
>> }
>> }
>
> So your point is that std.concurrency.Generator isn't so nice?
> Not advertised?
> Or do you simply want to have a keyword that wraps a function
> into generator like function* in ES6?
>
> ---
> auto fib = (int limit){
> import std.concurrency;
> return new Generator!int((){
> int a = 1, b = 1;
> while (a < limit)
> {
> a.yield; //syntactic sugar
> auto t = a;
> a = b;
> b = t + b;
> }
> });
> };
> ---
>
> https://run.dlang.io/is/xQl0Ir
It's not about how nice is a solution, it's about how easy is for
someone to find out about a language feature and use it. D has a
library solution for everything that is missing from the core
language instead to include in the language well proven patterns.
That's why is complicated: one must learn about fibers, ask
himself why in the world he must use std.concurrency to obtain a
list of numbers and so on. Even the cluttered ((){ will scare a
potential learner.
This is the documentation for C#:
You use a *yield return* statement to return each element one at
a time.
You can use a *yield break* statement to end the iteration.
Now, as an exercise, please explain for a newbie in two sentences
the Generator class, the yield function and why should we need
concurrency and fibers stuff for this.
Modern languages are evolving over time, D had a good start
inspiring himself from popular language features (at that time I
suppose it was Java), now it's stalling trying to win an
impossible bet on C/C++ compatibility instead of evolving in its
own way. Features are dropped from the language and moved to
library solutions. Library solutions often result in
incomprehensible compiler error messages, and that's normal, the
compiler has not enough information to provide a decent error
message.
Is the concept of range a first class citizen in D? If yes, the
language must provide the necessary syntax for repetitive
patterns linked to ranges and hide behind the scene the details.
Are the fibers the de facto way to deal with concurrency in D? If
yes, the language must provide the necessary syntax to write
fiber-oriented code. This will not stop anyone to write his
state-of-the-art-hand-made range or fiber solution, but it will
help the potential learner to understand immediately how to deal
with ranges or fibers.
A similar remark I have for traits: a lot of emphasis is put on
compile time reflection, but to use it, you need to import 8200
lines of code from std.traits.
More information about the Digitalmars-d
mailing list