top | item 44656875

(no title)

minebreaker | 7 months ago

Fair criticism, but it's not really a practical problem. Usually a linter will catch them easily, and even when junior devs ignore the warnings, you can just tell them to use "equals."

The thing is that, equality is the difficult problem. "equals" in JVM languages has a lot of problems. Dynamic languages are much more horrible in this aspect. JavaScript `==` is much worse than Java. Python is guilty too in my view, for using `__eq__` method. The only language I know which solves the problem correctly is Haskell. (Or, `Eq` in Cats)

discuss

order

saghm|7 months ago

It's a subjective thing, but to me, having the usage be intuitive even if it means doing a custom implementation is a bit less intuitive is still "simpler". A person in their first day of writing Python code can use `s == "some_string"` and it will work like they expect, and they typically will only need to learn about `__eq__` when they've spent a lot more time writing Python code. With Java, they might literally have to learn that `s == "some_string"` won't work the way they expect and that they need to use `.equals` instead.

JavaScript has an entirely different level of issues, where at first glance it _looks_ like `==` works the way you'd expect, and the issues start cropping up when you accidentally rely on assumptions like equality being transitive. I agree that this is much worse than Java, but it doesn't change the fact that Java still doesn't strike me as the simple, straightforward language you tout it to be. I'd argue that the measure of how simple it is to learn a language should be measured both by how quickly you run into behavior where you need to start caring about the underlying implementation and by how intuitive (or unintuitive) the underlying behavior you need to care about is. At least with regards to comparing equality, Python beats Java by that measure because it abstracts away the concerns about how to define equality from the concerns about how to actually perform the comparisons, and Java beats JavaScript because the extra knowledge you need to be able to compare equality correctly being way more straightforward.