Search: in
Named parameter
Named parameter Encyclopedia
  Tutorials     Encyclopedia     Dictionary     Directory  
Named_parameter Email this to a friend      Named_parameter

Named parameter

In computer programming, named parameters refers to a computer language's support for function calls that clearly state the name of each parameter within the function call itself.

Contents


Overview

A function call using named parameters differs from a regular function call in that the values are passed by associating each one with a parameter name, instead of providing an ordered list of values.

For example, consider the following Java method call that does not use named parameters:

window.addNewControl("Title", 20, 50, 100, 50, true);

Using named parameters in Objective-C, the call can be written as:

The Objective-C version is more explicit, while the Java version is more concise. Depending on the particular instance, a programmer may find one or the other easier to read. Also, depending on the specific language used, using named parameters may allow you to change the order in which you list them. (e.g.: Ada)

Usage in Languages

Named parameters are not used in languages like Java and C/C++. They are supported in languages like Ada, PL/SQL, Smalltalk, R, Mathematica, MATLAB, Python, Common Lisp, Visual Basic, and Objective C. In Objective Caml, named parameters are called labels.

Emulating

One may be able to achieve a similar effect in other languages (such as C) that do not have named parameters, by using either comments or a data structure:

With comments (in C):

Note that if using comments as above, the order of the arguments becomes important.

With a data structure (in C):

Notes

A good IDE provides the programmer with the same information in a much more concise form through the use of tooltips and lists. For example, Eclipse does this for Java. The same applies to other languages that have that kind of IDE.

Note that named parameters in some languages (such as Smalltalk and Objective-C) refers to the syntactical presentation and not to the underlying implementation. Neither language supports named parameters in the sense that Python supports key=value parameters. For example, in the above Objective-C fragment, the method name is literally "addNewControlWithTitle:xPosition:yPosition:width:height:drawingNow:".





Source: Wikipedia | The above article is available under the GNU FDL. | Edit this article



Related Links in Named parameter

Search for Named parameter in Tutorials
Search for Named parameter in Encyclopedia
Search for Named parameter in Dictionary
Search for Named parameter in Open Directory
Search for Named parameter in Store
Search for Named parameter in PriceGig



Help build the largest human-edited directory on the web.
Submit a Site - Open Directory Project - Become an Editor

Advertisement

Advertisement



Named parameter
Named_parameter top Named_parameter

Home - Add TutorGig to Your Site - Disclaimer

©2008-2009 TutorGig.com. All Rights Reserved. Privacy Statement