4 ms·
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 al
by spyremeown 3y 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.
- foobarbecue 3y agoIn 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?
- roflyear 3y agoI 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.
- flir 3y agoPHP exists in a place where everything's a string (HTTPland). Type coercion makes more sense there.
- foobarbecue 3y agoOh 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.
- hn_throwaway_99 3y agoPretty 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.
- giantrobot 3y ago> 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.
- flir 3y agoShouldn't that logic also apply to ==, which overloads the assignment operator (=) in the same way?
- hn_throwaway_99 3y agoVery much agree with this one, but would phrase it as using = to represent assignment was the bad original choice.
- giantrobot 3y agoIf the average keyboard had support, characters like ≡ could be used as the equivalence sigil and ≢ for not equivalent.
- seanalltogether 3y agoAs 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.
- LinAGKar 3y agoNo, here they were both the same type, but they were cast to int anyway.
- seanalltogether 3y agoI 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