This is a common pattern for initialisers at the moment:

class Foo

{

let foo : String

let bar : String

let barCount : Int

let baz : Int


init(foo: String, bar: String, baz: Int)

{

self.foo = foo

self.bar = bar

self.baz = baz

barCount = bar.characters.count

}

}

This involves a lot of using 'self.'. For those who prefer not to use
'self.' explicitly everywhere, this is probably the main place it gets
used. It's a lot of boilerplate code.

How would it be if, like default variables, we could pack some of that
information into the argument tuple, and unify parameters with properties
immediately?

class Foo

{

let foo : String

let bar : String

let barCount : Int

let baz : Int


init(self.foo: String, self.bar: String, self.baz: Int)

{

barCount = bar.characters.count

}

}

Less boilerplate, more focus on the properties which need to be generated.

Thoughts?
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to