Function overloading: Difference between revisions

Content deleted Content added
Rules in function overloading: Fixed grammar and opinionated language, completely removed strongly opinionated paragraph with extremely bad grammar comparing to parametric/ad-hoc polymorphism.
Tags: Mobile edit Mobile web edit
Line 52:
</ref>
 
Function overloading is usually associated with [[statically-typed]] programming languages that enforce [[type checking]] in [[function call]]s. OverloadedAn overloaded function is really just a set of different functions that happenare tocallable havewith 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}}
 
Sometime overloading wrongly taken as 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 or/and number of parameters.
The mistake comed from confusion in each form of static polymorphism as following:
* ''[[Parametric polymorphism]]'' differs 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) 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 differs from forms of [[Polymorphism (computer science)|polymorphism]] where the choice is made at runtime, e.g. through [[virtual function]]s, instead of statically.