"using the result of a comma expression is not allowed"

Timon Gehr timon.gehr at gmx.ch
Tue Apr 23 02:29:18 UTC 2024


On 4/22/24 15:21, Don Allen wrote:
> On Sunday, 21 April 2024 at 23:32:21 UTC, Timon Gehr wrote:
>> On 4/21/24 21:16, Don Allen wrote:
>>> And I think it's bad practice to support a hobbled version of a 
>>> common construct in anticipation of a use of the same syntax that 
>>> hasn't happened yet and has been in the pipeline for years.
>>
>> That is just one part of the rationale (that is probably on top of 
>> people's mind now as there has been some recent movement on tuples).
>>
>> https://dlang.org/deprecate#Using%20the%20result%20of%20a%20comma%20expression
>>
>> In any case, I don't understand why you focus on the tuple use case.
> 
> Excuse me. ...

No offense had been taken.

> I focused on tuples because 
> it came up repeatedly in the responses to my original post. You note 
> that yourself above. So I don't understand why you didn't understand.
> ...

Because your response was to a post that gave a more nuanced and more 
complete answer, with the proper weight given to the different arguments.

>> ...
>>
>> There are many ways to write any given piece of code and the variant 
>> with the comma operator is hardly ever the best one.
> 
> You haven't seen the situation where I attempted to use it as I would 
> have in C, have you?
> ...

Feel free to share.

>>
>>> I think this was a mistake in C and a bigger mistake in D, since we 
>>> know more now about language design than when Dennis Ritchie designed 
>>> C about 55 years ago.
>>
>> One of the things we know now is that comma expressions were a bad 
>> design of syntax. We should probably just have something like `let 
>> statement in expression` expressions instead.
> 
> You may have missed my point,

I did not.

> which was that value-returning block 
> expressions are a better way than comma expressions to allow 
> multi-statement sequences to provide a value, as in Rust:
> 
> ````
> let foo:i64 = if predicate
>                {
>                 stmta1;
>                 stmta2;
>                 expra1
>                }
>                else
>                {
>                 stmtb1;
>                 stmtb2;
>                 exprb1
>                };
> ````
> Something similar exists in Zig, though I don't think their syntax is as 
> elegant as Rust's in this case.
> 

This does not clash with tuple syntax.


More information about the Digitalmars-d mailing list