I would like let rules to be consistent whether you have a memberwise init or not; and I would like them to be consistent with classes.
I think this places me on Guillaume's side here. Félix > Le 22 déc. 2015 à 14:20:47, Guillaume Lessard via swift-evolution > <[email protected]> a écrit : > > >> On 22 déc. 2015, at 12:02, Matthew Johnson <[email protected]> wrote: >> >> This is not an attempt to subvert `let` properties. The `= 1` in the >> declaration can very reasonably be viewed as a default value that should be >> used if the member is not otherwise initialized. > > I see it as a definition. > > >> Why would you have an immutable instance member that is always going to have >> a constant value of 1? > > I’m not convinced the language must prevent people from doing useless things. > The current model is clear. The one you suggest is much murkier. > (And this is a kind of situation where I would expect nifty optimizations.) > > >> That just wastes space by duplicating the constant value in many instances. >> However it is quite reasonable to have an immutable instance member that >> defaults to 1, but may have a different value depending on the initializer >> that is used for the instance. > > Shouldn’t one write an initializer with a default value, then? > > struct A { > let property: Int > init(property: Int = 1) { self.property = property } > } > > Much clearer. Using initialized `let` properties as a mere suggestion > involves mental gymnastics. > > Guillaume Lessard > > _______________________________________________ > swift-evolution mailing list > [email protected] > https://lists.swift.org/mailman/listinfo/swift-evolution _______________________________________________ swift-evolution mailing list [email protected] https://lists.swift.org/mailman/listinfo/swift-evolution
