What is the point of having two different names for the same parameter?

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.


I'm not sold on the issue of having different internal and external names either.

Having or not having external names makes sense to me.

object.BeepXTimes(6) doesn't need an external name for it's parameter because the function name implies the meaning of the parameter.

The rationale, I think, is that sometimes the naming of a function's external parameters is phrased to make sense to the caller in a sentence:

someView.animateInWithDuration(0.25, withTimingFunction: .easeIn)

The external name withTimingFunction makes the function call read like a sentence, but withTimingFunction makes a lousy internal parameter name. You would probably want your parameter name to be just timingFunction. Having separate internal and external parameter names lets you do that.

For me, though, the extra complexity this requires in the function definition doesn't seem worth it. The good news is that the default is to create parameters using the same name for both internal and external parameter names, so the standard syntax is simple and easy to read.