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

Jacob Bandes-Storch jtbandes at gmail.com
Mon Jan 30 21:34:27 CST 2017


Although there's no spelling for this...
https://bugs.swift.org/browse/SR-3550
On Mon, Jan 30, 2017 at 7:29 PM Joe Groff via swift-evolution <
swift-evolution at swift.org> wrote:

>
> > 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.
>
> -Joe
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170131/84d44ff9/attachment.html>


More information about the swift-evolution mailing list