[swift-evolution] [Pitch] Custom Namespaces
Howard Lovatt
howard.lovatt at gmail.com
Fri Apr 1 18:15:01 CDT 2016
Yes something in this space might be useful, but, and this is a significant
but, we do have modules and files to break code into. So it wouldn't be a
top priority.
On Wednesday, 30 March 2016, Niels Andriesse via swift-evolution <
swift-evolution at swift.org> wrote:
> At the moment, it's not possible to define custom namespaces. They can be
> emulated using static members on an enum:
>
> enum Foo {
> static var bar: Bar
> static func baz() { }
> }
>
> This is not ideal, because:
>
> - The case shown above is semantically speaking obviously not an enum and
> shouldn't be presented as such.
> - The members are required to be static unnecessarily.
> - Not all top-level declarations can be nested like this (e.g.
> protocols).
> - If we allow namespaces to be reused in different files within the
> same module, this could potentially be used as a custom scope for access
> control (e.g. using the proposed private(...) syntax, so in this case
> private(Foo)).
>
> Are there any plans to allow custom namespaces (for example as shown
> below)?
>
> namespace Foo {
> var bar: Bar
> func baz() { }
> }
>
> Alternatively, a similar situation could be achieved by introducing
> submodules.
>
--
-- Howard.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160402/996a335e/attachment.html>
More information about the swift-evolution
mailing list