Why Java Doesn't Need Operator Overloading (and Very Few Languages Do, Really)

Robert Fraser fraserofthenight at gmail.com
Tue Apr 14 16:18:24 PDT 2009


Paul D. Anderson wrote:
> Sounds like someone needs a strong dose of D!!
> 
> http://java.dzone.com/articles/why-java-doesnt-need-operator
> 
> The comments bounce between "operator overloading is always bad because you can do idiotic things with it" and "operator overloading is essential because sometimes you really need it".
> 
> How about a language where operator overloading is available for the cases where you do really need it, but isn't available in general?
> 
> Hmmm...
> 
> Paul

OT: that article mentioned one of my biggest pet peeves:
""Doesn't it make much more sense to use add() for a List and put() for 
a Map?""

In that case it doesn't matter too much since the interface for the two 
functions is different. However, adding a single element to a collection 
should have an add() (or +=, or whatever), so that the type of the 
collection can be changed/abstracted away (e.x. made a template 
argument). This is particularly annoying with "enqueue"/"push" and 
"dequeue"/"pop", since there are often times you'd want to change 
between stacks and queues without changing the algorithm used.



More information about the Digitalmars-d mailing list