对于相同的参数有两个不同的名称有什么意义? [英] What is the point of having two different names for the same parameter?

查看:103
本文介绍了对于相同的参数有两个不同的名称有什么意义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  func mapEachElement(inArray arr:[Int],withFunc aFunc:(Int))

为什么会有inArray,然后是arr......有什么意义?

与withFunc和aFunc相同,它使得代码变得更复杂,阅读也变得混乱,为什么它们还被使用?

inArray是调用者的外部名称的函数应该在传递参数时使用。 arr是函数实现者在实现中用来引用参数的内部名称。您不必提供外部名称,这使得它更具可读性。它更像是使Objective-C函数的swift函数名称和参数可读。


func mapEachElement (inArray arr: [Int],  withFunc aFunc: (Int))

Why would there be "inArray and then "arr"...what's the point?

Same for "withFunc and "aFunc", it makes it more code complicated and also messier to read, why are they even used?

解决方案

inArray is external name which the caller of the function should use when passing parameters. arr is the internal name which the function implementer uses in the implementation to refer to the parameter. You don't have to supply external name.It makes it more readable. It is more like to make swift function names and parameters readable as Objective-C functions are.

这篇关于对于相同的参数有两个不同的名称有什么意义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆