aarjav
11/28/2018, 5:48 PMian.shaun.thomas
11/28/2018, 5:49 PMRuckus
11/28/2018, 6:00 PMfunc greet(person: String, from hometown: String) -> String {
return "Hello \(person)! Glad you could visit from \(hometown)."
}
print(greet(person: "Bill", from: "Cupertino"))
// Prints "Hello Bill! Glad you could visit from Cupertino."
Inside the function the variable is hometown
, but outside the function the variable is from
.
(Personally I don't like the idea at all, especially as the user is required to use them when present.)ian.shaun.thomas
11/28/2018, 6:02 PMRuckus
11/28/2018, 6:03 PMian.shaun.thomas
11/28/2018, 6:03 PMRuckus
11/28/2018, 6:05 PMian.shaun.thomas
11/28/2018, 6:06 PMRuckus
11/28/2018, 6:10 PMaarjav
11/28/2018, 6:54 PMcomputeSum(a=1,b=2)
to computeSum(of=1,and=2)
. There have been times where names for caller look good but awakward in fun body: = of + and
vs a + b
. other argument names are with, by, using, then. I guess its not very useful in most cases and could cause misunderstandings/bugs.ian.shaun.thomas
11/28/2018, 6:55 PMaarjav
11/28/2018, 7:06 PMRuckus
11/28/2018, 7:21 PMa
and b
would make more sense in your example, since there's nothing requiring argument order when using named arguments (there's nothing stopping the user from using computeSum(and = 2, of = 1)
, which makes a lot less sense than computeSum(b = 2, a = 1)
where it's more immediately obvious I'm switching the order of the values).
If it really is a concern, you could always add some sort of inline fun computeSumFluent(of: Int, and: Int) = computeSum(of, and)
gildor
11/29/2018, 2:21 AM