March 26, 2014 Re: Should we deprecate comma? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Byron | On Tuesday, 25 March 2014 at 14:00:28 UTC, Byron wrote:
> 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.
We use chained ternaries in our code regularly, and had no problem with them, with more than average programmers on the project. In my experience syntax didn't cause a single bug.
|
March 26, 2014 Re: Should we deprecate comma? | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile | On Tuesday, 25 March 2014 at 13:08:59 UTC, bearophile wrote: > Steve Teale: > I classify that as quite tricky code, it's a negative example :-( > > Bye, > bearophile I was not recommending it, I was just trying to think of when I'd used comma, and that popped into my head. Basically I agree that it is likely to introduce errors (like mine in my example perhaps ;=), though in that case the compiler catches it.) I could certainly live without it Steve |
Copyright © 1999-2021 by the D Language Foundation