Hacker News new | ask | show | jobs
by saghm 325 days ago
I get the point you're trying to make, but there's something ironic about touting a language as "simple" immediately followed by mentioning that using the basic equality operator that's used by pretty much every other mainstream language is "madness". I know every language has warts, but that one is pretty egregious both in terms of how quickly people would run into it for the first time and how easily it could have been avoided (e.g. by using something else for the less commonly needed equality operator, like how Python uses `is`). Having things that look correct and compile fine but then fall for reasons that you have to explicitly learn isn't really "simple".
1 comments

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)

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.