allevato
(Tony Allevato)
March 1, 2020, 5:54pm
3
This has been discussed a few times in the past, but I don't believe anyone has taken it as far as writing up an official proposal and implementation. I'd love to see it happen since the syntax would pair nicely with the use of extensions to organize code.
I have been using empty enums as "namespaces" and have been pretty pleased with how that has played out. Unfortunately, it leads to undesirable indentation as a level of indentation is required to declare a nested type:
enum Foo {}
// elsewhere:
extension Foo {
struct Bar {
}
}
This level of indentation is not required when extending the nested type:
extension Foo.Bar {
}
I have considered experimenting with this layout to eliminate the indentation:
extension Foo { struct Bar {
}}…
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 {}
…
6 Likes