Worst ideas/features in programming languages?

Timon Gehr timon.gehr at gmx.ch
Thu Jan 6 13:05:01 UTC 2022


On 1/6/22 08:14, bauss wrote:
> On Wednesday, 5 January 2022 at 22:42:14 UTC, Paul Backus wrote:
>> On Wednesday, 5 January 2022 at 07:28:41 UTC, Timon Gehr wrote:
>>>
>>> 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.)
>>
>> This mechanism seems too powerful to me; for example, one could write 
>> code like the following:
>>
>>     struct S {
>>         string opArgs;
>>     }
>>
>>     string fun(S s) { return "S overload"; }
>>     string fun(string s) { return "string overload"; }
>>
>>     void main() {
>>         assert(fun(S()) == "S overload"); // fails
>>     }
>>
>> If there is to be any mechanism for automatic expansion of tuples, it 
>> should probably be narrow enough to avoid enabling surprises like this 
>> one.
> 
> You could just make sure that the root type is always used if an 
> overload is available for it.
> 
> Just like if you did:
> 
> ```d
> struct S {
>    string opArgs;
>    alias opArgs this;
> }
> ```

No, if you want the root type, add a trailing comma to the declaration:

string fun(S s,){ return "S overload"; }
string fun(string s){ return "string overload"; }

(This matches unary tuple syntax (1,).)




More information about the Digitalmars-d mailing list