Re:Dennis Ritchie on the priorities of && || vs. == etc. (1982)
by JonChesterfield on Friday January 05, 2024 @05:30PM
(#38885909)
Consider (&& a b) and (|| a b) for no uncertainty over operator precedence and easy variadic representation (&& a b c) at the cost of zero additional parentheses.
[ Parent
| on HN ]
Re:Dennis Ritchie on the priorities of && || vs. == etc. (1982)
by namrog84 on Friday January 05, 2024 @05:34PM
(#38885948)
While true and might be easy to read in the example context of a b c I'd imagine having the && separator in real world conditions to be far more readable and clear for vast majority if people
Re:Dennis Ritchie on the priorities of && || vs. == etc. (1982)
by TylerE on Friday January 05, 2024 @07:37PM
(#38887018)
Pipe looks far too much like a 1 or lowercase ell.
Re:Dennis Ritchie on the priorities of && || vs. == etc. (1982)
by trealira on Saturday January 06, 2024 @04:13AM
(#38889841)
I actually think the variadic logical and is more readable, and wish more languages had it. As long as all the arguments are lined up vertically, you can think of it as a sequence of tests for true that exits at the first failure. It's more obvious with the variadic operator. Contrived comparison:
if (a != null && x != 0 && a.use_it(x))
{
...
}
(if (and (not (null a))
(/= 0 x)
(use-it a x))
...)
Re:Dennis Ritchie on the priorities of && || vs. == etc. (1982)
by NegativeLatency on Friday January 05, 2024 @05:35PM
(#38885971)
Most, and possibly all languages I've used day to day do not have prefix operators like that.
Re:Dennis Ritchie on the priorities of && || vs. == etc. (1982)
by ant6n on Friday January 05, 2024 @06:04PM
(#38886274)
Prefix operators considered harmful for readability.
Re:Dennis Ritchie on the priorities of && || vs. == etc. (1982)
by tasty_freeze on Friday January 05, 2024 @08:37PM
(#38887433)
... at the cost of having parentheses around every subexpression.