为什么Swift函数定义语法是多余的?

huangapple go评论80阅读模式
英文:

Why is Swift function definition syntax redundant?

问题

在C/C++/Java/Go中,我们使用逗号来分隔参数:

(a int, b int)

在Objective C中,我们使用冒号来表示参数:

:(int)a :(int)b

在Swift中,我们必须同时使用冒号和逗号:

(a:int, b:int)

这种冗余是必要的吗?

英文:

In C/C++/Java/Go, we use , to separate parameters:

(a int, b int)

In Objective C, we use : to indicate parameters:

:(int)a :(int)b

In Swift, we have to use both : and , :

(a:int, b:int)

Is the redundancy necessary?

答案1

得分: 2

Swift可能有外部和内部参数名:

(外部 内部:Int)
如果没有明显的分隔符,这将导致很多歧义。

英文:

Swift might have external and internal parameter names:

(external internal:Int)

It would create a lot of ambiguity if there wasn't distinctive separators.

答案2

得分: 1

这不是多余的,只是将C中的 替换为:。(当然还要调换类型和标识符。)

英文:

This is not redundant but simply replacing C's with a :. (And of course turning around type and identifier.)

huangapple
  • 本文由 发表于 2014年12月18日 15:45:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/27541538.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定