Named parameter

Uses your system voice; voice and rate in settings.

Snapshot

≈ 2 min read

Names in other languages

No names in other languages are held for this entry yet.

Article bodies are English and are not machine-translated. A name in another language is not a translation of the article.

In computer programming, named parameters, named-parameter arguments, named arguments or keyword arguments refer to a computer language's support for function calls to clearly associate each argument with a given parameter within the function call.

In computer programming, named parameters, named-parameter arguments, named arguments or keyword arguments refer to a computer language's support for function calls to clearly associate each argument with a given parameter within the function call. window.addNewControl("Title", 20, 50, 100, 50, true); Using named parameters in Python, the call can be written as: window.add_new_control(title="Title", x_position=20, y_position=50, width=100, height=50, drawing_now=True) Using named parameters in PHP, the call can be written as: $window->addNewControl(title: "Title", xPosition: 20, yPosition: 50, width: 100, height: 50, drawingNow: true); The version with positional arguments is more implicit. The versions that name parameters are more explicit. Depending on circumstance, a programmer may find one or the other to be easier to read. struct A { int a{}, int b{} }; void foo(A bar) { std::println("A.a = {}, A.b = {}", bar.a, bar.b); } foo({ .a = 1, .b = 3 }); MyFunctionCall( 20, /* x coordinate */ 50, /* y coordinate */ 100, /* width */ 5, /* height */ TRUE /* drawing now? */ ); Such comments are not checked for correctness and the order of arguments remains important. MyFunctionCall({ xPosition: 20, yPosition: 50, width: 100, height: 5, drawingNow: true }); MyFunctionCall({ width: 100, height: 5, xPosition: 20, yPosition: 50, drawingNow: true }); Compare to C99: struct MyParam { int xPosition; int yPosition; int width; int height; unsigned char drawingNow; }; … MyParam parameters = { .xPosition = 20, .yPosition = 50, .width = 100, .height = 5, .drawingNow = TRUE }; MyFunctionCall(&parameters); ==See also== Help:Template for named and positional parameters. Fluent interface Tag (programming) ==References== ==External links== https://web.archive.org/web/20070502112455/http://plg.uwaterloo.ca/~rgesteve/cforall/named_pars.html In C++ this paradigm can be easily implemented: Boost Parameter Library Named Parameters in various programming languages at Rosetta Code

Text derived from https://en.wikipedia.org/w/index.php?oldid=1361027741 under CC BY-SA 4.0; modifications have been made.

Sources cited in this revision

Extracted from the cited revision's reference blocks; absent citations are not invented.