[swift-evolution] Proposal: Allow "flat" declaration of nested types

Alexander Doloz adoloz at cayugasoft.com
Sat Nov 19 17:48:22 CST 2016


Hello, Swift community!

Right now, when we declare nested types in Swift, we have to literally nest them:

// Swift 3
struct A {
	var a = 0
	struct B {
		var b = 0
		struct C {
			var c = 0
			func someFunc() {
				if something {

				}
			}
		}
	}
}

By nesting types this way we waste amount of indents we can do without losing readability. In the example above, code inside if statement will already be far away from left border. 
I propose to allow do nested types like this:

// Proposal
struct A {
	var a = 0
}

struct A.B {
	var b = 0
}

struct A.B.C {
	var c = 0
	func someFunc() {
		if something {

		}
	}
}

No more unnecessary indentation. 
Of course, the old way should also continue to work. 




More information about the swift-evolution mailing list