ID:1250157
 
(See the best response by Zaoshi.)
Problem description:
I don't see any documentation on the possibility of overriding operators and yet there have been no questions about it seems over all of the entirety of the forums.

Is it possible to do any form of overriding operators in Byond, specifically that of comparison operators (as that's where it'd make the most sense)? The application is in object-oriented programming where a proc may not exactly know the proc that is used for a specific comparison, such as would be most useful in a Sort proc that could be shared over several different types of objects, especially considering the possible of lists with multiple types of objects.

Example:
//-------------------------------------------------------------
Person
var
name
age

New()
src.name = ""
src.age = 0

// Lacking /proc as per overriding in DM.
// Comparison operator procs
isEqualTo(var/Person/person)
var/isEqual = 0
if(src.name == person.name)
isEqual = 1
return isEqual

isGreaterThan(var/Person/person)
var/isGreater = 0
if(src.name > person.name)
isEqual = 1
return isEqual

isGreaterOrEqualThan(var/Person/person)
var/isGreaterOrEqual = 0
if(src.name >= person.name)
isGreaterOrEqual = 1
return isEqual
// ...
//-------------------------------------------------------------
proc
Sort(var/Person/firstPerson, var/Person/secondPerson)
if(firstPerson > secondPerson)
// ...

return
//-------------------------------------------------------------
Best response
It's not possible.
It's also up for debate whether or not operator overriding is entirely intuitive behaviour for comparison operators. Is dog >= cat?
Well it's assuming comparing objects to the same type of object.
Well, that's kind of the issue, DM's operators (like other languages) apply across types.

That said, lets assume we fix these overrides to be type-restricted. What does dog1 >= dog2 tell you as a programmer? It's more a conceptual issue, that different languages take different approaches on, according to philosophy.

C++'s argument is basically "Hey, whatever goes, I don't care", hence they have it. Appropriate use it of course can be very intuitive. What I've found it more useful for in C++, is stream read/write (<< >> in C++) operators actually, and I suspect DM could benefit from that instead, for sending textual messages to datums to be relayed on, like they were objects.

Java's argument is "It doesn't really work across teams, it muddles the logic", and for comparison, I'd agree. DM, being mostly a first language for people, should definitely be conscious of that.

That said, it's ultimately syntactic sugar, unless you are allowing comparison across types.
It's just a lot clearer to do "a.name > b.name" than just "a > b". Plus, that actually does something.
Well, I can make an argument in favour of operator overriding for say, UUIDs, or something like a DatedLogEntry datum or some such. Hence C++'s argument that appropriate use of it can be very intuitive. So I possibly wouldn't write it off straight away.

Then concern is more readability as you've noted, and of course help overhead. Imagine if you can (and people do readily) override operators, and you get developer help posts where you're not sure if they've done so or not. It adds a certain complication to the proceedings for both the user and the helper.
In response to Stephen001
The only time I've ever actually wanted to override operators is when dealing with a vector object, hehe. If you know what vectors are, the syntax should be pretty clear. I mean, the comparison operators probably wouldn't be as clear as the arithmetic operators (I guess they'd compare magnitude), but they would be really nice to have.