|
|
|
|
|
by ridiculous_fish
3319 days ago
|
|
Named parameters are very much the default in Swift. Positional parameters are rare exceptions. The internal/external name divide often works out beautifully. For example, let's equip Double with a multiply-add. An idiomatic Swift signature: extension Double {
func multiply(by multiplier:Double, adding summand:Double) -> Double {
return self * multiplier + summand
}
}
print(3.multiply(by:4, adding:5))
Erase punctuation and you have: func multiply by multiplier adding summand
print 3 multiply by 4 adding 5
The caller sees an action (multiply by, adding), the callee sees nouns (multiplier, summand). It's fantastically readable. |
|