Content deleted Content added
I have "overriding" and "overloading" somewhat mixed in my head, maybe it's not just me |
|||
Line 38:
==Rules in function overloading==
* The same function name is used for more than one function definition
* The functions must differ either by the [[arity]] or types of their parameters
It is a classification of static polymorphism in which a function call is resolved using some "best match" algorithm, where the particular function to call is resolved by finding the best match of the formal parameter types with the actual parameter types. The details of this algorithm vary from language to language.▼
Function overloading is usually associated with [[statically-typed]] programming languages that enforce [[type checking]] in [[function call]]s. An overloaded function is really just a set of different functions that happen to have the same name. For any particular call, the compiler determines which overloaded function to use, and resolves this at [[compile time]]. This is true for programming languages such as Java.{{sfn|Bloch|2018|loc=§Chapter 8 Item 52: Use overloading judiciously|p=238-244}}
▲
The mistake comed from confusion in each form of static polymorphism as following:
* ''[[Parametric polymorphism]]'' differ from overloading by that the function definition exists only ones and this function invoked with parameters of different types which are substituted formal parameter types.
* ''[[Ad hoc polymorphism]]'' is very similar to overloading but it's depends of a language. This classification was introduced by [[Christopher Strachey]] in 1967, but difference is that he applied for compiler specific features which was exists in some programming languages. It was possibly to define in a module only name of a function and have in another module a multiple functions with same name(exact [[Function overloading|function overloading]]) so one module doesn't have access to another module until compiled. Thus was created effect that in first module was used same function for different parameters but it was just a cosmetic effect therefore [[Christopher Strachey]] gave it such special name as "ad hoc". But not any language has same feature, e.g. in [[Java (programming language)|Java]], there is no possibility define such function, similar example in Java can be achieved by using common interface for both modules but interface should have exact function signature thus ''[[Ad hoc polymorphism]]'' can't be applied.
Function overloading should not be confused with forms of [[Polymorphism (computer science)|polymorphism]] where the choice is made at runtime, e.g. through [[virtual function]]s, instead of statically.
|