FACTOID # 15: A mere 0.8% of West Virginians were born in a foreign country.
 
 Home   Encyclopedia   Statistics   States A-Z   Flags   Maps   FAQ   About 
   
 
WHAT'S NEW
 

SEARCH ALL

FACTS & STATISTICS    Advanced view

Search encyclopedia, statistics and forums:

 

 

(* = Graphable)

 

 


Encyclopedia > Operator overloading

In computer programming, operator overloading (less commonly known as operator ad-hoc polymorphism) is a specific case of polymorphism in which some or all of operators like +, = or == have different implementations depending on the types of their arguments. Operators need not always be symbols. (dubious assertion) Sometimes the overloadings are defined by the language, sometimes the programmer can implement support for new types. Computer programming (often simply programming or coding) is the craft of writing a set of commands or instructions that can later be compiled and/or interpreted and then inherently transformed to an executable that an electronic machine can execute or run. Programming requires mainly logic, but has elements of science... Look up Ad hoc in Wiktionary, the free dictionary. ... In computer science, polymorphism means allowing a single definition to be used with different types of data (specifically, different classes of objects). ... In computer science, polymorphism means allowing a single definition to be used with different types of data (specifically, different classes of objects). ... Programming languages generally have a set of operators that are similar to operators in mathematics: they are somehow special functions. ...


Operator overloading (operator syntax and overloading generally) is usually only syntactic sugar. Despite this it is useful because it allows the developer to program using notation closer to the target domain and allows user types to look like types built into the language. It can easily be emulated using function calls; for an example, consider for integers a, b, c: Syntactic sugar is a term coined by Peter J. Landin for additions to the syntax of a computer language that do not affect its expressiveness but make it sweeter for humans to use. ...

 a + b × c 

In a language that supports operator overloading this is effectively a more concise way of writing:

 operator_add_integers (a, operator_multiply_integers (b,c)) 

(Assuming the × operator has higher precedence than +.) Precedence is a simple ordering, based on either importance or sequence. ...


However, in C++ templates or even C macros, operator overloading is needed in writing down generic, primitive operations such as summing elements when implementing a vector template. The only way to write primitive addition is a + b and this works for all types of elements only because of its overloading. (Actually, in C++ one could define an overloaded function add to use instead, but not in C.)


A more general variant of operator overloading, called expression reduction, allows expressions containing one or multiple operators to be reduced to a single function call. The expression above could be reduced to:

 operator_add_and_multiply_integers(a, b, c) 

Criticisms

Operator overloading has been criticized because it allows programmers to give operators completely different functionality depending on the types of their operands. C++'s usage of the << operator is an example of this problem. The expression C++ (generally pronounced /si plÊŒs plÊŒs/) is a general-purpose, high-level programming language with low-level facilities. ...

 a << 1 

will return twice the value of a if a is an integer variable, but if a is an output stream instead this will write "1" to it. Because operator overloading allows the original programmer to change the usual semantics of an operator and to catch any subsequent programmers by surprise, it is usually considered good practice to use operator overloading with care.


The common reply to this criticism, given by programmers who favor operator overloading, is that the same argument applies to function overloading as well. Further, even in absence of overloading, a programmer can define a function to do something totally different from what would be expected from its name. An issue that remains is that languages such as C++ provide a limited set of operator symbols, thus removing from programmers the option of choosing a more suitable operator symbol for their new operation.


Another, more subtle issue with operators is that certain rules from mathematics can be expected or unintentionally assumed. For example, a + b usually (but not always) means the same as b + a, but "school" + "bag" is different from "bag" + "school" in languages that overload + for string concatenation. The same kind of difference exists in the world of mathematics, where some matrix operations are not commutative. In mathematics, especially abstract algebra, a binary operation * on a set S is commutative if x * y = y * x for all x and y in S. Otherwise * is noncommutative. ...


Catalog

A classification of some common programming languages by whether their operators are overloadable by the programmer and whether the operators are limited to a predefined set.

Operators Not overloadable Overloadable
Limited set
New definable

Notes: C is a general-purpose, procedural, imperative computer programming language developed in 1972 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system. ... Java is an object-oriented programming language developed by James Gosling and colleagues at Sun Microsystems in the early 1990s. ... Js redirects here. ... Objective-C, often referred to as ObjC or more seldomly as Objective C or Obj-C, is an object oriented programming language implemented as an extension to C. It is used primarily on Mac OS X and GNUstep, two environments based on the OpenStep standard, and is the primary language... Pascal is one of the landmark computer programming languages on which generations of students cut their teeth and variants of which are still widely used today. ... Screenshot of Atari BASIC, one of the first BASIC languages for small computers. ... PHP (PHP: Hypertext Preprocessor) is a reflective programming language originally designed for producing dynamic Web pages. ... Ada is a structured, statically typed programming language, designed by Jean Ichbiah of Cii Honeywell Bull in the 1970s. ... C++ (generally pronounced /si plÊŒs plÊŒs/) is a general-purpose, high-level programming language with low-level facilities. ... The title given to this article is incorrect due to technical limitations. ... D is an object-oriented, imperative system programming language designed by Walter Bright of Digital Mars as a re-engineering of C/C++. He has done this by re-designing many C++ features, and borrowing ideas from other programming languages. ... // Early History at Apple Object Pascal was a creation of Niklaus Wirth and Larry Tesler. ... Perl, also Practical Extraction and Report Language (a backronym, see below) is a dynamic procedural programming language designed by Larry Wall and first released in 1987. ... Python is an interpreted programming language created by Guido van Rossum in 1990. ... Visual Basic . ... ML is a general-purpose functional programming language developed by Robin Milner and others in the late 1970s at the University of Edinburgh, whose syntax is inspired by ISWIM. Historically, ML stands for metalanguage as it was conceived to develop proof tactics in the LCF theorem prover (the language of... Pico is a programming language developed at the PROG lab at the Dutch-speaking Free University of Brussels (Vrije Universiteit Brussel, VUB). ... ALGOL 68 (short for ALGOrithmic Language 1968) is an imperative computer programming language that was conceived as a successor to the ALGOL 60 programming language, designed with the goal of a much wider scope of application and a more rigorously defined syntax and semantics. ... Fortran (previously FORTRAN[1]) is a general-purpose[2], procedural,[3] imperative programming language that is especially suited to numeric computation and scientific computing. ... Haskell is a standardized pure functional programming language with non-strict semantics, named after the logician Haskell Curry. ... Lisp is a family of computer programming languages with a long history and a distinctive fully-parenthesized syntax. ... Prolog is a logic programming language. ... Ruby is a reflective, object-oriented programming language. ... Perl 6 is the next version of the Perl programming language, currently under development. ... Smalltalk is an object-oriented, dynamically typed, reflective programming language. ... Eiffel is an ISO-standardized object-oriented programming language designed for extensibility, reusability, reliability and programmer productivity. ...

  1. ^ binary functions with a symbolic name can be called infix
  2. ^ introduced in Fortran 90
  3. ^ type classes instead of overloading
  4. ^ operators use the same prefix syntax as functions

Polish notation, also known as prefix notation was created by Jan &#321;ukasiewicz. ... For other uses, see Syntax (disambiguation). ...

See also


  Results from FactBites:
 
Operator overloading - Wikipedia, the free encyclopedia (555 words)
However, in C++ templates or even C macros, operator overloading is needed in writing down generic, primitive operations such as summing elements when implementing a vector template.
Operator overloading has been criticized because it allows programmers to give operators completely different functionality depending on the types of their operands.
Because operator overloading allows the original programmer to change the usual semantics of an operator and to catch any subsequent programmers by surprise, it is usually considered good practice to use operator overloading with care.
  More results at FactBites »

 
 

COMMENTARY     


Share your thoughts, questions and commentary here
Your name
Your comments

Want to know more?
Search encyclopedia, statistics and forums:

 


Press Releases |  Feeds | Contact
The Wikipedia article included on this page is licensed under the GFDL.
Images may be subject to relevant owners' copyright.
All other elements are (c) copyright NationMaster.com 2003-5. All Rights Reserved.
Usage implies agreement with terms, 1022, m