A simple question... Is it good practice to define a function accepting more than 1 parameter through tuples?
I explain myself better: I have a function:
let myfunc par1 par2 = ...;;
Is it good to to so?
let myfunc (par1, par2) = ...;;
When I say "is it good" I am saying: is it good practice? is it good to do this ALWAYS as a common practice to pass parameters to a function??
Thank you
A parameter is a named variable passed into a function. Parameter variables are used to import arguments into functions. For example: function example(parameter) { console.
The parameters, in a function call, are the function's arguments. JavaScript arguments are passed by value: The function only gets to know the values, not the argument's locations. If a function changes an argument's value, it does not change the parameter's original value.
A variable represents a concept or an item whose magnitude can be represented by a number, i.e. measured quantitatively. Variables are called variables because they vary, i.e. they can have a variety of values. Thus a variable can be considered as a quantity which assumes a variety of values in a particular problem.
The terms parameter and argument can be used for the same thing: information that are passed into a function. From a function's perspective: A parameter is the variable listed inside the parentheses in the function definition. An argument is the value that is sent to the function when it is called.
Normal F# style is to define functions curried, i.e. non-tupled according to your first example.
Currying lets you do this: ("partial application")
let myfunc par1 par2 = ...
let myfuncHello = myfunc "Hello"
myfuncHello "World" // same as: myfunc "Hello" "World"
However, if you expose your code to .NET languages other than F#, stick with tupling, since it's hard to call curried functions except from F#.
Edit: from the brand new F# Snippets site: http://fssnip.net/I
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With