Why does a function call require the parameter name in Swift?

后端 未结 6 1222
夕颜
夕颜 2020-11-27 10:42

I have this Function in a class:

func multiply(factor1:Int, factor2:Int) -> Int{
    return factor1 * factor2
}

I try to call the functi

6条回答
  •  臣服心动
    2020-11-27 11:13

    The reason is historical. This is how it worked in Smalltalk and it survived into its descendants. Squeak, Scratch, Blockly, Objective C and Swift.

    The kiddy languages (Squeak, Scratch and Blockly) held to it, because beginning programmers tend to struggle with the arity and parameter order. That was the original reason why Smalltalk did it that way. I do not know why ObjC and Swift decided to adopt the convention, but they did.

提交回复
热议问题