[swift-evolution] [proposal] Allow "let" for computed propertieswhich only reference immutable data

Leonardo Pessoa me at lmpessoa.com
Wed May 18 08:19:13 CDT 2016


Would it solve the issue if we had lazy let initialisers as I mentioned?

-----Original Message-----
From: "David Sweeris" <davesweeris at mac.com>
Sent: ‎18/‎05/‎2016 06:08 AM
To: "Leonardo Pessoa" <me at lmpessoa.com>
Cc: "Swift-evolution" <swift-evolution at swift.org>
Subject: Re: [swift-evolution] [proposal] Allow "let" for computed propertieswhich only reference immutable data

`lazy` properties can't be `let`. Personally, I disagree with this — their initial mutation is transparent, and it's conceptually perfectly valid to have a value that's, say, too expensive to calculate during every instance's init and whose value never changes once calculated — but there may well be Very Good Reasons for needing them to be `var`.

- Dave Sweeris


On May 17, 2016, at 17:23, Leonardo Pessoa <me at lmpessoa.com> wrote:


David, I'm thinking about the side effects calling a computed property has and although I see some use cases for let properties I also see workarounds. For example, a lazy initialiser will solve the issue of running a certain code only once and caching its value. I also start to think that any case in this proposal will be solved by lazy initialisers thus rendering it unnecessary.




On 17 May 2016 at 17:50, David Sweeris <davesweeris at mac.com> wrote:

You can't, if you're extending a pre-existing type.

I'd think that it might be possible to do some caching if the compiler knows that a computed property is constant, but maybe it doesn't work that way.


- Dave Sweeris

On May 17, 2016, at 14:40, Leonardo Pessoa via swift-evolution <swift-evolution at swift.org> wrote:


If the value of the property is a constant, shouldn't you just declare it as one? If you have any sort of computation in it, even concatenating two constant strings, can you really say this is a constant? And you would also be overloading the compiler into trying to check for every property you use let if the overall computation is constant or not. IMO, let isn't really the most appropriate keyword to use for properties.


- Leonardo


On 13 May 2016 at 04:44, Andru Felipe Zuniga via swift-evolution <swift-evolution at swift.org> wrote:

It would be useful for clarification of a computed property being constant in extensions. For example:

extension SKSpriteNode {
        static let type: String {
                return “Sprite”
        }
}

Andru



_______________________________________________
swift-evolution mailing list
swift-evolution at swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution



_______________________________________________
swift-evolution mailing list
swift-evolution at swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160518/588f12f4/attachment.html>


More information about the swift-evolution mailing list