[swift-evolution] Unify `static` and `class` keywords

Chris Lattner clattner at apple.com
Wed Dec 9 00:01:17 CST 2015

> On Dec 7, 2015, at 7:12 PM, Ling Wang via swift-evolution <swift-evolution at swift.org> wrote:
> Now I understand your concerns. But you misunderstood my proposal. I'll restate my points about “type properties”:
> 1. Stored class properties(let’s call them “class instance variables” for better discussion about “stored type properties” below) are not very useful or needed. So we are not likely to add them to Swift. This one we both agree. So there is only one kind of stored properties for types and they are stored like global variables, which are now called “static stored properties“. 
> 2. `type` properties in my proposal covers both stored properties and calculated properties. Except for the `type` keyword, the way they are declared are exactly the same as that of instance properties:
> ```
> class Foo {
>     type let i = 1 // stored type property
>     type var k: Int { // calculated type property
>         return 1
>     }
> } 
> ```
> 3. Since we’ve already excluded “class instance variables” in point 1, stored type properies in my proposal are certainly not “class instance variables”. They behave the same as the current “static stored properties”. This is where you misunderstood me. 
> So you don’t need the `final` keyword to make them “static”. If they are “stored”(VS calculated) they are “static”. We just don’t use `static` as the keyword.
> Static storage is the implementation details. Just like global variable declarations don’t need `static` keyword though they use static storage, stored type property declarations don’t need `static` keyword to denote they use static storage. After all there is only one kind of stored type properties.

The problem is one of consistency.  It would be very problematic for a “type var” to have one set of semantics, but a “type func” to have completely different semantics.  Also keep in mind that we *do* have *computed* static and computed class properties, today.


More information about the swift-evolution mailing list