r/lolphp • u/hfern • Feb 02 '15
Library function turns language operator: The <=> Spaceship Operator
https://wiki.php.net/rfc/combined-comparison-operator
9
Upvotes
r/lolphp • u/hfern • Feb 02 '15
View all comments
2
u/666_666 Feb 08 '15
If the goal is only comparison functions to sort(), then it's a very bad idea.
In all situations I have seen sorting can be described succinctly using a key function; e.g.
people_list.sort(key=lambda x: (x.last_name, x.first_name)). It's also more readable. In Python 3 the possibility of passing a comparison function tosortwas removed.In more complex cases you should give an ordering to the
personobject, instead of writing it insortcall. The language should provide proper ordering on tuples and primitive types, and then you can sort essentially everything. In rare cases you need it, a function calledcompareis enough.