March 25, 2014
On Tuesday, 25 March 2014 at 22:38:27 UTC, Timon Gehr wrote:
> What 'subtle semantics' or 'tricky behaviour'? It is straightforward. The introduced bugs are due to accidental usage caused by failure to match parentheses correctly. (i.e. comma removes some redundancy from the language syntax. This does not mean it is a difficult concept.)

I don't know about 'subtle semantics' or 'tricky behaviour'. It's not a difficult concept either, if you are willing to learn it. But it *is* one of the more "obscure" concepts.

Most "average" coders could spend an entire career and never care nor know the damn thing is actually an operator.
March 25, 2014
On Tue, Mar 25, 2014 at 12:45:26PM -0700, Andrei Alexandrescu wrote:
> On 3/25/14, 12:29 PM, captaindet wrote:
> >mwould this effect comma usage inside for-loops as well or will this be special cased?
> 
> Where inside for loops? -- Andrei

	for (x=1, y=2; x < 10 && y < 20; x++, y++) { ... }

My opinion is to just special-case the syntax for for-loops.


T

-- 
Unix is my IDE. -- Justin Whear
March 25, 2014
On 3/25/14, 4:08 PM, H. S. Teoh wrote:
> On Tue, Mar 25, 2014 at 12:45:26PM -0700, Andrei Alexandrescu wrote:
>> On 3/25/14, 12:29 PM, captaindet wrote:
>>> mwould this effect comma usage inside for-loops as well or will this be
>>> special cased?
>>
>> Where inside for loops? -- Andrei
>
> 	for (x=1, y=2; x < 10 && y < 20; x++, y++) { ... }
>
> My opinion is to just special-case the syntax for for-loops.

The proposed change would allow the code above, but not this:

for (x=1, y=2; x++, x < 10 && y < 20; y++) { ... }


Andrei
March 25, 2014
On Tuesday, 25 March 2014 at 23:16:32 UTC, Andrei Alexandrescu wrote:
> On 3/25/14, 4:08 PM, H. S. Teoh wrote:
>> On Tue, Mar 25, 2014 at 12:45:26PM -0700, Andrei Alexandrescu wrote:
>>> On 3/25/14, 12:29 PM, captaindet wrote:
>>>> mwould this effect comma usage inside for-loops as well or will this be
>>>> special cased?
>>>
>>> Where inside for loops? -- Andrei
>>
>> 	for (x=1, y=2; x < 10 && y < 20; x++, y++) { ... }
>>
>> My opinion is to just special-case the syntax for for-loops.
>
> The proposed change would allow the code above, but not this:
>
> for (x=1, y=2; x++, x < 10 && y < 20; y++) { ... }
>
>
> Andrei

What term should we design to this type of expression? r-value?
March 26, 2014
On Tuesday, 25 March 2014 at 17:58:45 UTC, bearophile wrote:
> I think total removal of the comma operator could offer more readable D code.

No, complete removal will make code less readable. Why can't you read commas?
March 26, 2014
>
> The proposed change would allow the code above, but not this:
>
> for (x=1, y=2; x++, x < 10 && y < 20; y++) { ... }
>
>
> Andrei

After the change in D this code would generate a warning/error?
If that's so then the "does the same as C code or fails to
compile" objective is still being met.
March 26, 2014
On 03/26/2014 10:19 AM, Jason King wrote:
>>
>> The proposed change would allow the code above, but not this:
>>
>> for (x=1, y=2; x++, x < 10 && y < 20; y++) { ... }
>>
>>
>> Andrei
>
> After the change in D this code would generate a warning/error?
> If that's so then the "does the same as C code or fails to
> compile" objective is still being met.

(x++, x < 10) would be a void rather than bool if I understand correctly, so this wouldn't compile.

March 26, 2014
Kagamin:

> No, complete removal will make code less readable.

Why? Can you show examples?


> Why can't you read commas?

When I read code quickly I sometimes mistake what's the what part of the expression returned. C commas don't have a straightforward meaning.

Bye,
bearophile
March 26, 2014
On 3/26/14, Kagamin <spam@here.lot> wrote:
> On Tuesday, 25 March 2014 at 17:58:45 UTC, bearophile wrote:
>> I think total removal of the comma operator could offer more readable D code.
>
> No, complete removal will make code less readable. Why can't you read commas?

Have you never experienced this bug before?

enum vals = [
    "afoo01foo01",
    "bbar02foo02",
    "cdoo03foo03",
    "dfoo01foo04",
    "ebar02foo01",
    "fdoo03foo02",
    "gfoo01foo03",
    "hbar02foo04",
    "aidoo03foo01"
    "jfoo01foo02a",
    "kbar02foo03",
    "ldoo03foo04",
];

This has nothing to do with the comma operator, but what it has to do is with readability. The comma is easily misplaced.
March 26, 2014
Andrej Mitrovic:

> Have you never experienced this bug before?
>
> enum vals = [
>     "afoo01foo01",
>     "bbar02foo02",
>     "cdoo03foo03",
>     "dfoo01foo04",
>     "ebar02foo01",
>     "fdoo03foo02",
>     "gfoo01foo03",
>     "hbar02foo04",
>     "aidoo03foo01"
>     "jfoo01foo02a",
>     "kbar02foo03",
>     "ldoo03foo04",
> ];

Walter kind of agreed to remove that bug from D, but so far nothing has changed:
https://d.puremagic.com/issues/show_bug.cgi?id=3827

Bye,
bearophile