Which language futures make D overcompicated?

rumbu rumbu at rumbu.ro
Fri Feb 9 15:06:49 UTC 2018


On Friday, 9 February 2018 at 13:53:51 UTC, Seb wrote:
> On Friday, 9 February 2018 at 13:10:16 UTC, rumbu wrote:
>> On Friday, 9 February 2018 at 08:27:21 UTC, Nick Sabalausky 
>> (Abscissa) wrote:
>>
>>> Defining input ranges (one of my biggest pet peeves):
>>>
>>> C# knocked it out of the park ages ago with its design for a 
>>> stackless!!! (ie no-fibers) coroutine syntax. There's no 
>>> reason the same approach couldn't be used in D for creating 
>>> input ranges.
>>
>> I'm missing too the yield return and await syntax in D every 
>> time.
>
> What's wrong with the library solution from std.concurrency?


let's take the D's example from std.concurrency:

static void spawnedFunc(Tid ownerTid)
{
     receive((int i){
         received = text("Received the number ", i);

         // Send a message back to the owner thread
         // indicating success.
         send(ownerTid, true);
     });
}

rough C# translation:

async void spawnedFunc()
{
     int i = await receive();
}


> All good point. A few questions:
>
>> - alias this;
>
> Do you mean no multiple alias this or the problem with 
> overloading?

When I learnt D first time, it was a very difficult concept for 
me. Personally I don't find any use of it today.

>
>> - everything is a range. If not, we will rangify it.
>
>> Autodecoded eventually.
>
> No one likes it, but you can opt-out with byCodeUnit - that 
> doesn't work for you?

This topic was about how difficult is D to learn. Due to the 
obsessive "range them all" politics, you cannot really use most 
of the D library functions if you don't understand very well 
range concepts. And after you learn them, you'll have 
autodecoding surprises.

>
>> - no dedicated syntax sugar for ranges;
>
> What do you expect here?
> (also it's not entirely true - foreach already supports ranges)
>
>> - no dedicated syntax sugar for coroutines;
>
> What syntax sugar that can't be done by a library do you expect?

Let's take a classic range in D:

struct FibonacciRange(int limit)
{
     int a = 1, b = 1;

     bool empty() const @property
     {
        return a > limit;
     }

     int front() const @property
     {
         return a;
     }

     void popFront()
     {
         auto t = a;
         a = b;
         b = t + b;
     }
}

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;
    }
}

>
>> - no dedicated syntax sugar for events;
>
> What syntax sugar that can't be done by a library do you expect?
> await?

D library is using signals instead of events. Personally I find 
events easier to learn.



More information about the Digitalmars-d mailing list