March 25, 2014 Re: Should we deprecate comma? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Timon Gehr | On Tuesday, 25 March 2014 at 13:15:17 UTC, Timon Gehr 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: , = ?.
Even ternary operator itself isn't allowed in a lot of programming team.
|
March 25, 2014 Re: Should we deprecate comma? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | On Sunday, 23 March 2014 at 20:56:45 UTC, Andrei Alexandrescu wrote:
> Discuss: https://github.com/D-Programming-Language/dmd/pull/3399
>
> Andrei
+1
The comma operator is one of the most terrible things in C/C++.
Please, remove it from D.
P.S. C# also haven't got support of comma operator. Instead, it use comma for multidimensional array definition. It will de nice to have the same multidimensional array support in D.
|
March 25, 2014 Re: Should we deprecate comma? | ||||
---|---|---|---|---|
| ||||
Posted in reply to ilya-stromberg | ilya-stromberg:
> It will de nice to have the same multidimensional array support in D.
In D it's much better to define them in library code.
Bye,
bearophile
|
March 25, 2014 Re: Should we deprecate comma? | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile | On Tuesday, 25 March 2014 at 15:35:01 UTC, bearophile wrote:
> ilya-stromberg:
>
>> It will de nice to have the same multidimensional array support in D.
>
> In D it's much better to define them in library code.
>
> Bye,
> bearophile
May be you are right and in D world we should define multidimensional arrays in library code. I just want to say that C# has great syntax for multidimensional arrays.
|
March 25, 2014 Re: Should we deprecate comma? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Marc Schütz | On Tuesday, 25 March 2014 at 15:14:09 UTC, Marc Schütz wrote:
> 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.
I think it's supposed to test if first byte at s isn't '/' character ,s was a typo. I don't think it's a NOP because if I'm right, s is evaluated to begging of its address and it's always != 0. So, if it will always run.
|
March 25, 2014 Re: Should we deprecate comma? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Marc Schütz | "Marc Schütz" " wrote in message news:ljmioogmqpvipifrhsub@forum.dlang.org... > 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. It was supposed to check if the first character was not '/', but for some reason it was always taking the if branch. A similar one is while (x); doSomething(); Which is nearly impossible to see, and I do all the time by accident. Thankfully the compiler catches that one for us. |
March 25, 2014 Re: Should we deprecate comma? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Daniel Murphy | On Tuesday, 25 March 2014 at 16:14:27 UTC, Daniel Murphy wrote:
> "Marc Schütz" " wrote in message news:ljmioogmqpvipifrhsub@forum.dlang.org...
>
>> 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.
>
> It was supposed to check if the first character was not '/', but for some reason it was always taking the if branch.
Ok, so it was another argument against ",". I thought you were showing a new use-case, that's why I was confused...
|
March 25, 2014 Re: Should we deprecate comma? | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile | > A similar program in Haskell:
>
>
> foo (a, b) =
> show a ++ " - " ++ show b
>
> lst = [(10, 20), (30, 40)]
>
> main = do
> print $ map foo lst
>
>
> Output:
>
> ["10 - 20","30 - 40"]
>
> And Haskell is regarded as one of the safest languages :-)
>
> Similar code is possible in F#, OCaml, Scala, etc.
And in Rust:
fn first((value, _): (int, f64)) -> int { value }
Bye,
bearophile
|
March 25, 2014 Re: Should we deprecate comma? | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile | "Comma operators should be used sparingly. The most suitable uses are for constructs strongly related to each other, as in the for loop in reverse, and in macros where a multistep computation has to be single expression." (K&R). Kill it… D solves the use cases with other means. |
March 26, 2014 Re: Should we deprecate comma? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Timon Gehr | On Tuesday, 25 March 2014 at 13:15:17 UTC, Timon Gehr 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: , = ?.
Yes, I most likely used
atq = whatever? 0: (universal = true, 42);
|
Copyright © 1999-2021 by the D Language Foundation