March 25, 2014
On Monday, 24 March 2014 at 10:57:45 UTC, Regan Heath wrote:
> On Sun, 23 Mar 2014 20:56:25 -0000, Andrei Alexandrescu <SeeWebsiteForEmail@erdani.org> wrote:
>> Discuss: https://github.com/D-Programming-Language/dmd/pull/3399
>
> Would it have any effect on:
>
> int *p, q;
>
> R

I presume that

for (int i = 0, j = m;;) {}

Is in the same category?

The only place I have tended to use the comma operator is in ternary expressions

bool universal;

atq = whatever? 0: universal = true, 42;
March 25, 2014
Steve Teale:

> The only place I have tended to use the comma operator is in ternary expressions
>
> bool universal;
>
> atq = whatever? 0: universal = true, 42;

I classify that as quite tricky code, it's a negative example :-(

Bye,
bearophile
March 25, 2014
On 03/25/2014 02:08 PM, bearophile wrote:
> Steve Teale:
>
>> The only place I have tended to use the comma operator is in ternary
>> expressions
>>
>> bool universal;
>>
>> atq = whatever? 0: universal = true, 42;
>
> I classify that as quite tricky code, it's a negative example :-(
>
> Bye,
> bearophile

It's not tricky code. It is not even valid code. Operator precedence from lowest to highest: , = ?.
March 25, 2014
On Tue, 25 Mar 2014 13:15:16 -0000, Timon Gehr <timon.gehr@gmx.ch> wrote:

> On 03/25/2014 02:08 PM, bearophile wrote:
>> Steve Teale:
>>
>>> The only place I have tended to use the comma operator is in ternary
>>> expressions
>>>
>>> bool universal;
>>>
>>> atq = whatever? 0: universal = true, 42;
>>
>> I classify that as quite tricky code, it's a negative example :-(
>>
>> Bye,
>> bearophile
>
> It's not tricky code. It is not even valid code. Operator precedence from lowest to highest: , = ?.

Fixed:

atq = whatever ? 0 : (universal = true, 42);

Still a bad example.  Horrid code IMO.

R

-- 
Using Opera's revolutionary email client: http://www.opera.com/mail/
March 25, 2014
On Sun, 23 Mar 2014 20:09:45 -0700, Andrei Alexandrescu wrote:
> 
> That was in Phobos too. Fix:
> 
> int a = something == 1 ? 1
>         : something == 2 ? 2 : { assert(0); return 0; }();
> 
> There are of course other ways, too, including defining a function that returns its last argument.
> 
> 
> Andrei

This would be a red flag in my code review, nested ternaries are to hard to read and even worse for maintainability.  Been bit to many times with little bugs in them.  Wish compilers would throw a warning when they are used.
March 25, 2014
Byron:

> nested ternaries are to hard to read and even worse for
> maintainability.  Been bit to many times with little bugs
> in them.  Wish compilers would throw a warning when they
> are used.

Perhaps related:
https://d.puremagic.com/issues/show_bug.cgi?id=8757

On the other hand chained ternary operators are not too much uncommon.

Bye,
bearophile
March 25, 2014
On Tuesday, 25 March 2014 at 13:58:01 UTC, Regan Heath wrote:
> Fixed:
>
> atq = whatever ? 0 : (universal = true, 42);
>
> Still a bad example.  Horrid code IMO.
>
> R

Yeah, I'd likely object to it on code review and ask to re-write with plain if condition.
March 25, 2014
On 3/25/14, Dicebot <public@dicebot.lv> wrote:
> Yeah, I'd likely object to it on code review and ask to re-write with plain if condition.

This is my all-time favorite anti-feature:

void main()
{
    import std.stdio;
    bool False = false;
    writeln("the value is: " ~ False ? "true" : "false");
}
March 25, 2014
On Tuesday, 25 March 2014 at 12:43:07 UTC, Steve Teale wrote:
> On Monday, 24 March 2014 at 10:57:45 UTC, Regan Heath wrote:
>> On Sun, 23 Mar 2014 20:56:25 -0000, Andrei Alexandrescu <SeeWebsiteForEmail@erdani.org> wrote:
>>> Discuss: https://github.com/D-Programming-Language/dmd/pull/3399
>>
>> Would it have any effect on:
>>
>> int *p, q;
>>
>> R
>
> I presume that
>
> for (int i = 0, j = m;;) {}
>
> Is in the same category?

Yes, that's a declaration list, not a comma operator.
March 25, 2014
On Tuesday, 25 March 2014 at 11:54:25 UTC, Daniel Murphy wrote:
>
> I just introduced one in my own code:
>
> if (s[0] != '/', s)

What is it supposed to do? Do you want to check that s is at least 1 character long? Otherwise it's a NOP, AFAICS.