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

Ling Wang an00na at gmail.com
Wed Dec 9 10:51:33 CST 2015


Can you explain the inconsistency between the semantics of “type var” and “type func”?

I don’t see any inconsistency:
1. For calculated properties, “type var” and “type func” are essentially the same thing. My proposal doesn’t treat them differently.
2. For stored properties, “type var” and “type func” are totally different things, by definition. One is data, one is function. It is the same for instance properties and methods. This difference is inherent in object-orientated programming.

- Ling

> On Dec 9, 2015, at 12:01 AM, Chris Lattner <clattner at apple.com> wrote:
> 
> 
>> 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.
> 
> -Chris
> 



More information about the swift-evolution mailing list