Worst ideas/features in programming languages?

Timon Gehr timon.gehr at gmx.ch
Wed Jan 5 07:28:41 UTC 2022


On 05.01.22 07:33, Walter Bright wrote:
> On 1/3/2022 7:09 PM, Timon Gehr wrote:
>> My DIP draft extends "alias this" to allow this (which should work 
>> anyway):
>>
>> alias Seq(T...)=T;
>> struct S{
>>      byte b;
>>      int c;
>>      alias this=Seq!(b,c);
>> }
>>
>> void func(byte,int);
>>
>> func(S());
> 
> I confess, this makes me uneasy. `alias this` produced a lot of 
> unintended consequences. I'm gunshy of extending it. I'd prefer:
> 
>      func(S().tupleof);
> ...

Well, then let's not extend `alias this`.

> 
>> It does have some significant drawbacks, e.g. `foo(int,int)` and 
>> `foo((int,int))` would have a different ABI and the second overload 
>> can't be called as `foo(1,2);`...
> 
> I tried to actively avoid that :-)
> 
>> To be very clear, I want this:
>>
>> [(1,2),(3,4)].map!((a,b)=>a+b).each!writeln;
>>
>> An this is generally what people mean when they talk about "tuples".
> 
> I understand. It looks like a worthy goal.

How about something like opArgs, dealing specifically with this case? 
(i.e., a function call `foo(x)` with a single argument is immediately 
rewritten to `foo(x.opArgs)` if `x` has a member `opArgs`, and this 
rewrite is applied exactly once.)


More information about the Digitalmars-d mailing list