What is the most concise, unambiguous syntax for operator associated methods (for overloading etc.) that doesn't pollute the namespace?
- by Doug Treadwell
Python tends to add double underscores before its built-in or overloadable operator methods, like __add(), whereas C++ requires declaring overloaded operators as operator + (Thing& thing) { /* code */ } for example. Personally I like the operator syntax because it seems to be more explicit and keeps these operator overloading methods separated from other methods without introducing weird prefix notation. What are your thoughts?
Also, what about the case of built-in methods that are needed for the programming language to work properly? Is name mangling (like adding __ prefix or sys or something) the best solution here? What do you think about having another type of method declaration, like ... "system method" for lack of creativity at the moment.
So there would be two kinds of declarations:
int method_name() { ... }
system int method_name() { ... }
... and the call would need to be different to distinguish between them.
obj.method_name(); vs obj:method_name(); perhaps, assuming a language where : can be unambiguously used in this situation.
obj.method_name() vs obj.(system method_name)()
Sure, the latter is ugly, but the idea is to make the common case simple and system stuff should be kept out of the way.
Maybe the Objective-C notation of method calls? [obj method_name]?
Are there more alternatives? Please make suggestions.