3 ms·
The first returns bar if foo == bar, the second is dependent on the implementation of max(). There's a potential difference in behaviour.
by codeduck 5y ago
The first returns bar if foo == bar, the second is dependent on the implementation of max(). There's a potential difference in behaviour.
- rileymat2 5y agoI saw that too, but if there is a "real" difference in returning equal things, then it could indicate a way bigger problem in the design.
- withinboredom 5y agoIf you're using a language where there is a difference between value-equals and instance-equals, it could cause a very subtle bug by changing this code if the result of it was relying on an instance-equals later on.
- rileymat2 5y agoI agree it can introduce bugs, my point is relying on that is probably a design issue somewhere else. Because even in the first, you are relying on the order of max being the same everywhere it matters.
- withinboredom 5y agoMaybe. If it’s usage were in the scope of the current PR, I might suggest a fix like this. But if it might introduce something subtle, I probably wouldn’t suggest it or I’d ask if they had considered changing it as well as if there were any subtle issues to worry about. As someone who works in a multimillion line codebase that sees millions of executions daily since 2005, these are real issues and saying “it’s a design issue somewhere else” doesn’t exactly fly because that “somewhere else” may no longer have a team maintaining it.