Hacker News new | ask | show | jobs
by spyremeown 1168 days ago
The "triple equal" or "really really equal" or whatever we call it is the stupidest thing a language can have. If your language needs something like that, it already failed* somewhere along the way.

* Which doesn't imply it's not useful.

3 comments

As others are saying, I don't think "==" vs "===" are a bad thing, what is bad is allowing 2 objects of different types to be compared, which is really why this md5 bug occurs. The implicit coercion from one type into another automatically creates a rats nest of problems.
No, here they were both the same type, but they were cast to int anyway.
I understand, but the root cause is allowing equality checks between different types. As a result of that decision you need cascading rules on what conversions take higher priority then others. Clearly php has decided that when a string goes through an equality check against another object, that integer conversion is placed above byte comparison
In python, I find it pretty intuitive. It's very convenient to have "do these two objects have the same contents" vs "are these two the same object at the same memory address."

Other language design options are to use pointers / references, be strongly typed or be functional. Seems like you're saying all weakly-typed object-oriented languages are failures?

I don't think "===" in PHP is the same as "is" in Python, though? Identity is important (why would you want to check for 0, None, "", etc.. in separate cases, unless you want to?) but I don't think that is what "===" in PHP.
PHP exists in a place where everything's a string (HTTPland). Type coercion makes more sense there.
Oh you're right. I actually was thinking python "is" was written "===" because I got confused with javascript, yikes.

And I don't speak PHP.

Anyway yeah being able to compare identity and equivalence separately seems important.

Pretty hard disagree. There are fundamentally different definitions of "equal", and pretty much all languages I can think of support that (e.g. reference equality vs. Object.equals in Java).

You can argue that triple equals is a confusing syntax, but the underlying problem is inherent in the world we live in.

> You can argue that triple equals is a confusing syntax

To me this is the problem with triple equals. The different types of equality should be explicit in their use rather than overloading a sigil.

Shouldn't that logic also apply to ==, which overloads the assignment operator (=) in the same way?
Very much agree with this one, but would phrase it as using = to represent assignment was the bad original choice.
If the average keyboard had support, characters like ≡ could be used as the equivalence sigil and ≢ for not equivalent.