How is this achieved?
Code can be divided into modules, with some blocks being private or public. Private blocks in different modules can be given the same name.
Some programming languages allow overloading, where a block in the current scope hides blocks with the same name in outer scopes. Although blocks can be given the same name, only one at a time is ever available. Examples are method overloading in object oriented programming languages, and functions declared inside functions in procedural programming languages.
Namespaces allow public blocks residing in different modules to share the same name. Where there is ambiguity, the block's name is qualified by it's namespace.
Multimethods allow multiple code blocks to be in the same scope at the same time, and use some or all of the signature of the block to disambiguate.
The signature of a function or method is comprised of it's return type, it's name, and the types and number of it's parameters.
In the programming language C, 'int add(int, int)' and 'float add(float, float)' cannot be in the same scope together, although the signatures are different, in both their parameters and their return type.
In some programming languages, the value of parameters are also used to disambiguate.
Search Encyclopedia
|
Featured Article
|