Operator Overloading
Monkey Forums/Monkey Programming/Operator Overloading
| ||
Any way to do this? |
| ||
I don't know of any way, and I don't believe there is one. I really wish there was. |
| ||
No. I can see when it's useful, but I've seen it used where it hides/confuses functionality. I try to stay away from it. Java and javascript do not allow operator overloading, so it shouldn't be in monkey either. Use Methods for now (a.Add(b)) |
| ||
It makes code nicer when you are dealing with mathematical objects that have natural interpretations of operators. I would use it for things like Point and Size classes if it was there, but I can live happily enough without it. I don't see why Monkey should follow the rules of Java and Javascript. But I do see an argument against operator overloading which is that Monkey, despite being a sophisticated language, is also beginner-friendly, with a lot of syntax coming from Basic - and I'm not sure operator overloading fits well into that. |
| ||
"I don't see why Monkey should follow the rules of Java and Javascript" lowest common denominator, since monkey is translated to many |
| ||
lowest common denominator, since monkey is translated to many That would leave lots and lots of features we already have out, such as reflection, overloading, hardtyped nature, generics... |
| ||
lowest common denominator, since monkey is translated to many Operator overloading is determined at compile time, not run time. Hence its irrelevant if the target language supports it. Take C++ for example, its target compilation language definitely doesn't support generics, variable types (outside of different length words), objects, functions, operator overloading... etc. As such I personally would like to see a few of the more interesting features in Monkey. Though as Gerry said, one of the important constraints is to keep Monkey beginner friendly. |
| ||
Thanks for the replies, well I would have liked it for various reasons. I was surprised it is missing TBH but oh well, maybe I can make it a request for a future version then. |
| ||
sorry for my spread of misinfo then, glad I learned something in the process |