Questions tagged [named-parameters]

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.

371 questions
10
votes
2 answers

Is there a programming language that performs currying when named parameters are omitted?

Many functional programming languages have support for curried parameters. To support currying functions the parameters to the function are essentially a tuple where the last parameter can be omitted making a new function requiring a smaller…
10
votes
3 answers

Differences between using ? and :param in prepare statement

Let's say I want to select records where Id = 30. Prepared statements allow two ways of binding parameters: question marks $id = 30; $q = $conn->prepare("SELECT * FROM pdo_db WHERE id > ?"); $q->execute(array($id)); // Here above ID will be…
CodeWithCoffee
  • 1,896
  • 2
  • 14
  • 36
10
votes
2 answers

"Automatically insert all named arguments" at method call-site, in code

Say there is a method, void M(int a, int b, int c /* and many more */) Is there a way to transform M() to M(a: .., b: .., c: ..) at the call-site? I am using Visual Studio 2013 (Ultimate) 2017 Professional with ReSharper 8 ReSharper 2018.1. A…
user2864740
  • 60,010
  • 15
  • 145
  • 220
9
votes
1 answer

Scala Copy() Odd Behavior

I'm experiencing an odd bit of behavior when I use the auto-generated copy() method that was added in Scala-2.8. From what I've read, when you declare a given class as a case-class, a lot of things are auto-generated for you, one of which is the…
shj
  • 1,558
  • 17
  • 23
9
votes
10 answers

C# Named parameters to a string that replace to the parameter values

I want in a good performance way (I hope) replace a named parameter in my string to a named parameter from code, example, my string: "Hi {name}, do you like milk?" How could I replace the {name} by code, Regular expressions? To expensive? Which way…
mike
9
votes
6 answers

Better Way To Use C++ Named Parameter Idiom?

I've been developing a GUI library for Windows (as a personal side project, no aspirations of usefulness). For my main window class, I've set up a hierarchy of option classes (using the Named Parameter Idiom), because some options are shared and…
Head Geek
  • 38,128
  • 22
  • 77
  • 87
9
votes
3 answers

Optional arguments with default value in Ruby

I would like to create a function that has optional arguments with default values def my_function(a = nil, b=nil, c=500) end and call the function with the arguments I would like to specify only my_function(b=100) How do I accomplish this in Ruby…
AdamNYC
  • 19,887
  • 29
  • 98
  • 154
9
votes
2 answers

Should I call Parameters.Clear when reusing a SqlCommand with a transation?

I'm coding a transaction manually in ADO.NET. The example I'm working from reuses the SqlCommand which seem like a fine idea. However, I have added parameters to my command. My question is: in the following code, is command.Parameters.Clear()…
Aaron Anodide
  • 16,906
  • 15
  • 62
  • 121
9
votes
1 answer

Ocaml's named parameters

Trying to understand Ocaml's mechanism for named parameters. I understand the basics, but the doc shows an example like this: # let f ~x ~y = x - y;; val f : x:int -> y:int -> int = # let x = 3 and y = 2 in f ~x ~y;; - : int = 1 What exactly…
scry
  • 1,237
  • 12
  • 29
9
votes
2 answers

Why aren't named parameters used more often?

I have designed a parameter class which allows me to write code like this: //define parameter typedef basic_config_param name; void test(config_param param) { if(param.has()) { //by name cout << "Your name is: " <<…
Fredrik
  • 893
  • 2
  • 10
  • 20
8
votes
2 answers

C# : overloading constructors with optional parameters & named arguments?

This isn't a question on proper coding practice, I'm just working through the semantics. lets say I have the following constructors... public FooClass(string name = "theFoo") { fooName = name; } public FooClass(string name, int num = 7, bool boo =…
user1229895
  • 2,259
  • 8
  • 24
  • 26
8
votes
6 answers

Is it possible to skip parameters that have default values in a function call?

I have this: function foo($a='apple', $b='brown', $c='Capulet') { // do something } Is something like this possible: foo('aardvark', , 'Montague');
sprugman
  • 19,351
  • 35
  • 110
  • 163
8
votes
2 answers

Is there any tools to help me refactor a method call from using position-based to name-based parameters

I wish to transform code like: var p = new Person("Ian", "Smith", 40, 16) To: var p = new Person(surname: "Ian", givenName:"Smith", weight:40, age:16) As a first step in making the code more readable, I am willing to use a 3rd party refactoring…
Ian Ringrose
  • 51,220
  • 55
  • 213
  • 317
8
votes
2 answers

How to have optional named arguments in Groovy method

Using the documented mixture of named and positional arguments (or args with default values for that matter), how to invoke a method without specifying any named param? I'm trying to extend existing shared method without breaking everybody else's…
Sunny Milenov
  • 21,990
  • 6
  • 80
  • 106
8
votes
2 answers

Stored procedure with named parameter and calculation

I'm calling a stored procedure with named parameter. exec MySP @name = 'binesh', @amount = @amt, @date = @date It's working fine for me. But when I'm trying exec MySP2 @name = 'binesh', @amount = -@amt, @date = @date or exec MySP3 @name =…