[openstreetmap/openstreetmap-website] Rubocop autofix: ambiguous operator precedence (PR #3523)
Andy Allan
notifications at github.com
Wed Apr 6 17:03:12 UTC 2022
Sure, I can see that and I can usually remember the rules too. But I think it becomes more useful here to use brackets when we're not talking about simple mathematical symbols. There's a fair amount of complexity when reading things like:
```
... captures[1].to_f
... captures[1].to_f + captures[2].to_f
... captures[1].to_f + captures[2].to_f / 60
```
I mean, you need to read the captures bit, then think about the array access, then converting it to a float, and then keep on reading in case there's a higher-precedence operator still to follow. Similarly for the max_friends calculations:
```
max_friends = account_age_in_hours.ceil + recent_friends - active_reports * 10
```
It's a lot of stuff to read and mentally juggle before you get to the multiplication, because each part of the calculation is not just a simple symbol like `x y z i j k` etc.
So I think the braces are worthwhile in giving a heads-up that something is being done out-of-order, given the complexity of reading some of the components in these lines. And I don't think the extraneous braces make the other lines any harder to read.
--
Reply to this email directly or view it on GitHub:
https://github.com/openstreetmap/openstreetmap-website/pull/3523#issuecomment-1090498269
You are receiving this because you are subscribed to this thread.
Message ID: <openstreetmap/openstreetmap-website/pull/3523/c1090498269 at github.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/rails-dev/attachments/20220406/dd1e807b/attachment-0001.htm>
More information about the rails-dev
mailing list