Talk:Operator overloading

From Wikipedia, the free encyclopedia

I removed this text:

Similarly, and with operators in PostgreSQL, where mathematical transformations can be defined on operators and PostgreSQL may use many optimalizations to expressions that use them.

Because I couldn't decipher what the original author was trying to express. If someone can clarify the intent of this passage and wants to put the content back into the article, please do so. Neilc 02:26, 11 Aug 2004 (UTC)


Contents

[edit] more than implicit aesthetics

Operator overloading provides more than an aesthetic benefit when the language allows operators to be invoked implicitly in some circumstances. For example, this is the case with to_s operator in Ruby, which returns a string representation of an object.

This doesn't make sense to me. How is it more than aesthetic? Is there other difference if you just write the invocation? I think the point is there might be a difference between function call semantics and operator semantics (such as a + b might choose between a.add and b.add)

it depends upon if you assume that there exist other overloadable methods/functions/whatever or not. If operator overloading is the only overloading, it does add more than aesthetic.

By the way, you could add Lisp to the language classification :-)

Ok, I removed this until someone can explain how it makes sense. --TuukkaH 15:40:05, 2005-09-07 (UTC)

[edit] Declaring new operators

What is meant by "declaring new operators"? 62.194.114.150 10:20, 28 Nov 2004 (UTC)

Using operator symbols in the language that have no default meanings, like an operator *** or ## for instance. Pico allows this. Wouter Lievens 10:48, 6 Mar 2005 (UTC)

[edit] Criticism

The criticism counts for all language features, so it is a red herring, imho.

Example:

a.addToList(b); // this function call sends an e-mail to Bill Gates

This is also an example of giving something a bad name (or bad semantics). The criticism is thus irrelevant. Wouter Lievens 10:48, 6 Mar 2005 (UTC)

It may be a red herring, but it is also the commonest criticism of overloading. The purpose of Wikipedia is to describe things as they are, not to evaluate them: our job is to report what critics actually say, relevant or not, not to try to evaluate whether things are good or bad ourselves. Haeleth 14:49, September 6, 2005 (UTC)

[edit] First language with Operator Overloading

It would be interesting to identify the first language to introduce operator overloading. Anyone know if any language before ALGOL 68 (1968) implemented it?

Rwendland 02:05, 6 Apr 2005 (UTC)

[edit] Gutter talk?

I've removed the "gutter talk" section, which (if you can't be bothered to check History) was about how what absolutely everyone calls "operator overloading" should really be called "operator overriding" unless a class exports more than one operator. Given that this is not a common criticism, nor is it supported by actual usage, I don't really think it's encyclopaedic content. (It was also of disputable accuracy.) Haeleth 14:49, September 6, 2005 (UTC)

[edit] Lisp

In lisp, (+ 3 5) adds 3 & 5. Lisp uses the same syntax for functions: (funcname arg1 arg2) etc. Because of this, defining new operators in lisp is as easy as defining a new function. Overriding an operator is the same as defining a new function. Because of this, I changed lisp's position in the chart to indicate that operators are overloadable and new operators are definable.--Dasunt 23:27, 3 March 2006 (UTC)

This is true only if you can have the function + converted into a generic, so you are later able to overload it for different classes. If you only override the previous function definition of the symbol + you're not overloading it. I think it can be done, but am not sure. --euyyn 22:25, 2 July 2006 (UTC)
As Lisp has dynamic typing and first class functions this is trivially true. You could assign the old implementation to some value, and then define a new function that checks the type of the argument and applies eighter the old implementation or a new one depending on the result. (CLOS also has inbuilt generic functions, but you dont realy need them to do overloading in lisp).

[edit] Ruby

How is it that Ruby permits new operators to be defined? It seems to me that only existing operators that are part of the syntax can be defined as methods in Ruby. If that's not what that axis of the chart means, perhaps it should be clarified.

You're right. We can't define new operators in Ruby. There's a limited set (language's operators, except the following: =, .., ..., !, not, ||, &&, and, or, ::). I'm going to remove it from the list. 01:02, 18 February 2007 (UTC)

[edit] Dubious statement regarding symbols and citations needed

The ISO/IEC 2382 Standard Vocabularies for IT define an operator as a symbol that identifies or represents an operation. The definition does not limit symbols to single characters. Thus '+', 'add', 'first', 'next' could all be operators.

It is in fact the symbol that is overloaded through reuse. While, hopefully, the operations have similar semantics, the operations are in fact different.

A more accurate statement would be: "Operators are not limited to single characters." As it is, this article appears to contradict a fundamental computing definition and to confuse a symbol with what it represents.

The article lacks citations for verifiability and runs the risk of violating No Original Research or No Point of View.

Bob Badour 15:22, 29 June 2006 (UTC)

Come on, in the sentence, the word symbol refers to what everybody understand as a symbol, i.e., a graphical/printed sign (in opposition to letters and numbers), not to the special meaning we in the field of programming also have for it. --euyyn 22:47, 2 July 2006 (UTC)
Clearly not everyone understands the word symbol the same. It should be clarified to show the intended meaning, perhaps with something like "punctuation characters," "graphical symbols," or "non-alphabetic characters."--69.181.83.91 16:06, 9 July 2006 (UTC)
Isn't the statement referring to something like C++'s conversion operators? 213.38.7.224 12:33, 7 July 2006 (UTC)

[edit] samples for expression reduction?

are there any known languages that support expression reduction (outside of the compiler)? —The preceding unsigned comment was added by 80.129.243.120 (talk) 23:45, 17 January 2007 (UTC).