[Pitch] Nesting types without nesting in place (additional)


(Adrian Zubarev) #1

As you may know we can nest types for shiny namespacing (protocol nesting might follow in Swift 3 as well).

What if we could create Types separated by a `.` character to determine that this is a nested type to stop building type pyramides, which could be/look ugly in some cases.

Imagine SomeClass and NestedClass are some huge and complex types. It might become hard to read if we had to build them in place just for good namespacing.

class SomeClass {
    
class NestedClass {
enum Error {}
}
enum Error {}
}

Split this to something like this:

class SomeClass {}

enum SomeClass.Error {}

class SomeClass.NestedClass {
enum Error {} // nesting is still allowed
}

Extensions already allow that.

extension SomeClass.NestedType {}

What do you think? Is it something for Swift 3?

···

--
Adrian Zubarev
Sent with Airmail


Syntax sugar for declaring nested types
(Adrian Zubarev) #2

May I revive this idea for a discussion.

When I posted this first I didn’t thought about creating these nested types inside extensions.

So basically I could do this (over and over):

extension SomeClass {
class NestedClass { … }
}

But we have to surround a new nested type by an extension scope which is more boilerplate to my eyes than just `class SomeClass.NestedClass` instead.

Is this worth a proposal?

···

--
Adrian Zubarev
Sent with Airmail

Am 12. Mai 2016 bei 16:04:23, Adrian Zubarev (adrian.zubarev@devandartist.com) schrieb:

As you may know we can nest types for shiny namespacing (protocol nesting might follow in Swift 3 as well).

What if we could create Types separated by a `.` character to determine that this is a nested type to stop building type pyramides, which could be/look ugly in some cases.

Imagine SomeClass and NestedClass are some huge and complex types. It might become hard to read if we had to build them in place just for good namespacing.

class SomeClass {
class NestedClass {
enum Error {}
}
enum Error {}
}

Split this to something like this:

class SomeClass {}

enum SomeClass.Error {}

class SomeClass.NestedClass {
enum Error {} // nesting is still allowed
}

Extensions already allow that.

extension SomeClass.NestedType {}

What do you think? Is it something for Swift 3?

--
Adrian Zubarev
Sent with Airmail


(John McCall) #3

You're welcome to submit a proposal, but I personally don't think I'd support it; this seems like it just creates another way to write something for very little benefit.

John.

···

On May 18, 2016, at 11:00 AM, Adrian Zubarev via swift-evolution <swift-evolution@swift.org> wrote:
May I revive this idea for a discussion.

When I posted this first I didn’t thought about creating these nested types inside extensions.

So basically I could do this (over and over):

extension SomeClass {
   class NestedClass { … }
}

But we have to surround a new nested type by an extension scope which is more boilerplate to my eyes than just `class SomeClass.NestedClass` instead.

Is this worth a proposal?