[swift-evolution] Why doesn't Swift allow a variable and a function with the same name?

Joe Groff jgroff at apple.com
Mon Jan 30 18:59:44 CST 2017

> On Jan 30, 2017, at 11:42 AM, Austin Zheng via swift-evolution <swift-evolution at swift.org> wrote:
> The reason Swift works like this is because you can assign a function value (independently of calling it) to a variable. So there aren't two separate namespaces separating function names and variable names.

To be honest, I would say that there's no "reason" for this, except as lingering effects of our early "functions have simple names, and arguments have labeled tuple type" model. If we had originally implemented the language with its current (at least aspirational) Smalltalk-ish compound-names model, we probably would have ended up allowing this, since the var and func do formally have different names. The ability to reference a function by only the first segment of its name is likewise legacy of the original model, though it happens to be useful since good naming hygiene encourages different base names for different things to begin with.


More information about the swift-evolution mailing list