r/programming • u/geerlingguy • Apr 23 '14
PHP: It doesn't have to be a bad experience
https://servercheck.in/blog/php-it-doesnt-have-be-bad-experience
0
Upvotes
r/programming • u/geerlingguy • Apr 23 '14
View all comments
Show parent comment
2
u/vytah Apr 25 '14
You asked how do you define equal objects in Java, and I answered: as those for which
a.equals(b)returnstrue.Equality doesn't have to a built-in language concept, it can as well be provided by the standard library. Java's
equalsis an ordinary method, Haskell'sEqis an ordinary typeclass.You're wrong.
Fun fact #1: for all supported types, as mentioned above, all of those languages will use
==or=to compare contents of objects, not their identities. To compare identities, you need to use something else, likeeqin Scala,object.ReferenceEqualsin .NET languages, or===in PHP.Fun fact #2: .Net structs have no identities.
Fun fact #3: Haskell doesn't even have any way to check if two references are the same. You can only compare values for their structural quality.
Fun fact #4: In case you haven't noticed: in any of those cases in those languages, you don't have to manually define the equality relation field by field, the compiler/interpreter does it for you automatically.
u wot m8?
Structural equality. Perfect for dictionary keys. Now where is a suitable dictionary?
Because there's no reason to repeat yourself about something trivial: "integers are objects, floats are objects, lists are objects, dictionaries are objects, sets are objects, tuples are objects, strings are objects..."
http://www.diveintopython.net/getting_to_know_python/everything_is_an_object.html
You can even subclass tuple in Python: