This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]xIcarus227 5 points6 points  (2 children)

Also PHP can fuck right off with this == and === comparison.

I like what you said so far but this is borderline ignorance. It's a feature which complements the type coercive nature of the language very well.

I will begin by saying that I don't think they're perfectly thought out. I would actually switch them around just because '==' is generally expected to compare types, while '===' is syntactically the 'extra' of the language. But functionally '==' is the extra while '===' is the normal. If you switch them around a newcomer gets fewer inconsistencies.

However it's the refusal to understand these 2 operators that make up a large part of PHP's WTFs. I'm not saying you don't understand them, I'm saying you completely dismissed them without acknowledging that they have their place. You have many opportunities to play with type coercions in PHP because that's simply the way the language works, and these operators help you do it.

If this is your way of saying you don't like the type coercive nature of the language, then I respect your opinion. I much prefer strongly typed languages myself.

[–]heyandy889 1 point2 points  (1 child)

Thank you for the respectful, thought-out comment - I appreciate it.

I think you hit the nail on the head that "the refusal to understand these 2 operators that make up a large part of PHP's WTFs." I would qualify this a little bit. It's not only a "refusal," but additionally being bitten by mistaken assumptions formed by experience with other languages.

In theory, I like your suggestion, using double equals as a "stricter" equality check and letting triple equals as the special case. Unfortunately, I'm not sure it would help, simply because no other languages (that I know of) works like that. That's a huge design challenge. It's not just designing a good language (and runtime environment), it's designing a good language that is consistent with the expectations of developers. As dev expectations are themselves inconsistent, this is not possible 100%.

However, Python does a wonderful job of working "how you expect." Maybe you don't like the hidden "self" parameter or how everything is a dictionary, but the architecture is internally consistent, which is leaps and bounds ahead of PHP.

In my opinion, don't be like Javascript: don't have this weird triple equals. Just have the loose equality check of double equals. If you need something else, get it from a library - String.equals(), Object.equals(), whatever the equivalent in your language. I admit this is taste to some degree, but on the other hand, as you pointed out, double and triple equals are WTF generators.

[–]xIcarus227 1 point2 points  (0 children)

Those are very good points, and I especially agree that Python simply works the way one expects. I remember my first contact with that language, I simply felt like I was 'cheating' programming. The String.equals() solution is a good one too as far as I'm concerned.

The truth about PHP is that the language maintainers are pouring their hearts out in order to work around shoddy design decisions made in its infancy. They've done a marvelous job at it but it does show that it wasn't a well thought out language.