Named parameters enable you to specify an argument for a particular parameter by associating the argument with the parameter's name rather than with the parameter's position in the parameter list.
Questions tagged [named-parameters]
371 questions
22
votes
4 answers
Can named arguments be used with Python enums?
Example:
class Planet(Enum):
MERCURY = (mass: 3.303e+23, radius: 2.4397e6)
def __init__(self, mass, radius):
self.mass = mass # in kilograms
self.radius = radius # in meters
Ref:…

kevinarpe
- 20,319
- 26
- 127
- 154
21
votes
3 answers
Can you combine named parameter with short-hand constructor parameter?
In dart:
Named parameters function like so-
String send(msg, {rate: 'First Class'}) {
return '${msg} was sent via ${rate}';
}
// you can use named parameters if the argument is optional
send("I'm poor", rate:'4th class'); // == "I'm poor was sent…

Jordan
- 1,003
- 2
- 12
- 24
20
votes
5 answers
Emulating named function parameters in PHP, good or bad idea?
Named function parameters can be emulated in PHP if I write functions like this
function pythonic(array $kwargs)
{
extract($kwargs);
// .. rest of the function body
}
// if params are optional or default values are required
function…

Imran
- 87,203
- 23
- 98
- 131
20
votes
3 answers
Named and optional parameters, and WCF
so .Net 4 added named and optional parameters which are pretty sweet. I don't need to make as many 1 line overload methods.
Will that work over WCF?

puffpio
- 3,402
- 6
- 36
- 41
20
votes
5 answers
Determine if a named parameter was passed
I would like to know if it is possible to determine if a function parameter with a default value was passed in Python.
For example, how does dict.pop work?
>>> {}.pop('test')
Traceback (most recent call last):
File "", line 1, in…

Jake
- 3,427
- 2
- 28
- 23
20
votes
2 answers
python sqlite insert named parameters or null
I'm trying to insert data from a dictionary into a database using named parameters. I have this working with a simple SQL statement e.g.
SQL = "INSERT INTO status (location, arrival, departure) VALUES (:location, :arrival,:departure)"
dict =…

user2497185
- 303
- 1
- 2
- 6
20
votes
10 answers
How to define named Parameters C#
This seems like a simple question, but for some reason I can't find the answer anywhere. Basically, I'd like to be able to implement a constructor that takes NamedParameters.
By named parameters, I do not mean parameters with default values…

Pierluc SS
- 3,138
- 7
- 31
- 44
19
votes
2 answers
Named Parameters and the params keyword in C#
I have a C# method with a variable length argument list declared using the params keyword:
public void VariableLengthParameterFunction (object firstParam,
params object[] secondParam)
Is there any way…

marosoaie
- 2,352
- 23
- 32
18
votes
3 answers
Is it possible for an optional argument value to depend on another argument in Scala
Does anyone know if something like this is possible in Scala:
case class Thing(property:String)
def f(thing:Thing, prop:String = thing.property) = println(prop)
The above code doesn't compile; giving the error error: not found: value thing at…

Kristian Domagala
- 3,686
- 20
- 22
18
votes
4 answers
When to use keyword arguments aka named parameters in Ruby
Ruby 2.0.0 supports keyword arguments (KA) and I wonder what the benefits/use-cases are of this feature in context of pure Ruby, especially when seen in light of the performance penalty due to the keyword matching that needs to be done every time a…

saihgala
- 5,724
- 3
- 34
- 31
17
votes
2 answers
Why doesn't MySQLi library natively support named parameters?
Proper MySQLi parameterized query syntax from http://php.net/manual/en/mysqli.quickstart.prepared-statements.php:
$stmt = $mysqli->prepare("INSERT INTO test(id) VALUES (?)");
$stmt->bind_param("i", $id);
But never something like:
$stmt =…

Dennis
- 7,907
- 11
- 65
- 115
16
votes
3 answers
What rules does HTML follow when constructing parameters?
I'm using Rails to auto-magically create child objects based on a complex set of nested attributes. Therefore, I need the parameters to be nested in a very particular way. Obviously I realize I can construct them however I want with JS, but I'd like…

james
- 3,989
- 8
- 47
- 102
16
votes
2 answers
"Error: The function applied to this argument has type ..." when using named parameters
I'm currently working through "Real Word OCaml", and one of the basic examples with named / labeled parameters doesn't seem to work (using utop 4.01.0):
let languages = ["OCaml"; "Perl"; "C"];;
List.map ~f:String.length languages;;
Produces:
Error:…

Frank Schmitt
- 30,195
- 12
- 73
- 107
15
votes
5 answers
Resharper - keep named parameters when doing code cleanup
We've adopted a convention that when calling a C# function with a "non-obvious" parameter, we use a named parameter even when it's not necessary.
E.g.
obj.Process(save: true)
rather than
obj.Process(true)
While it's unnecessary, it makes it a lot…

Stuart Moore
- 681
- 5
- 32
15
votes
5 answers
How do you curry the 2nd (or 3rd, 4th, ...) parameter in F# or any functional language?
I'm just starting up with F# and see how you can use currying to pre-load the 1st parameter to a function. But how would one do it with the 2nd, 3rd, or whatever other parameter? Would named parameters to make this easier? Are there any other…

Dax Fohl
- 10,654
- 6
- 46
- 90