Worst ideas/features in programming languages?

Timon Gehr timon.gehr at gmx.ch
Wed Jan 5 23:54:50 UTC 2022


On 1/5/22 23:37, Paul Backus wrote:
> On Wednesday, 5 January 2022 at 06:33:39 UTC, Walter Bright wrote:
>> On 1/3/2022 7:09 PM, Timon Gehr wrote:
>>> 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.
> 
> Is this really necessary or even desirable? Tuples do not auto-expand 

This is not about auto-expanding. Conceptually, functions with multiple 
arguments are functions that take a tuple argument. I am sure you are 
aware of this.

> like this in other languages.

Well, in _some_ languages. Those languages get it wrong.

> For example, in Python:
> 
>      def fun(*args):
>          print(len(args))
> 
>      tup = (1, 2, 3)
>      fun(1, 2, 3) # prints "3"
>      fun(tup) # prints "1"
> ...

Yes, and I dislike this about Python. Making multiple arguments a 
distinct concept from tuples on the surface is just not particularly 
good design. Why is _that_ desirable? It's a good example of 
non-orthogonal language design.

```d
void foo(int a, string b){} // pattern (int a,string b)
foo(1,"2"); // match tuple (1,"2")

(int a, string b) = (1,"2"); // same thing

void foo((int a, string b), double c){}

foo((1,"2"), 3.0);

((int a,string b), double c) = ((1,"2"),3.0);
```

Why would pattern matching tuples work differently in a parameter list 
and elsewhere?

> Even without automatic tuple expansion, Timon's example could be written 
> as follows:
> 
>      alias apply(alias fun) = (args) => fun(args.tupleof);
>      [(1,2), (3,4)].map!(apply!((a, b) => a+b)).each!writeln;

Clearly, but who wants to do that?


More information about the Digitalmars-d mailing list