[swift-evolution] Pre proposal: Should there be a way to distinguish class instances from struct instances
me at swizzlr.co
Thu Dec 17 14:30:48 CST 2015
I would be interested in exploring more responsive IDEs that could reveal this information contextually, rather than embedding it within the source files. In the same way we can option click on a decl and see the type, being able to surface that information in a useful manner would be ideal.
Sent from my iPhone
> On 17 Dec 2015, at 07:52, Sean Kosanovich via swift-evolution <swift-evolution at swift.org> wrote:
> I can definitely see value in knowing if you’re dealing with a Value or Reference Type. Of course, the easy answer is to just look at the documentation/definition, but that is slow.
> Likewise, pointer notation feels old and looks messy. I am not sure of a great way to show this, any suggestions?
>> On Dec 17, 2015, at 7:23 AM, Daniel Steinberg via swift-evolution <swift-evolution at swift.org> wrote:
>> The way in which we reason about instances of value types and instances of reference types is significantly different and yet there is no way to easily distinguish them in Swift.
>> In Objective-C, for example, if we have an NSDate and an NSTimeInterval we can tell that NSDate is a reference type and NSTimeInterval is a value type by looking at how it is used in code
>> NSDate *myDate = //…
>> NSTimeInterval someTimeInterval = //…
>> The “*” helps us see that myDate is a pointer to an instance of NSDate.
>> We see this in methods that return values as well
>> - (NSString *)aStrringReturningMethod // …
>> - (NSInteger)numberOfMistakesInThisEmail //...
>> I realize that this is a result of Objective-C living in C’s world and we don’t have that constraint in Swift.
>> However, this means that when the semantics of variables, parameters, properties, and return values from methods is not always clear in our code. Because structs can have methods in Swift it is all to easy to confuse an instance of a struct with an instance of a class.
>> I may be alone here, but I think it would be less confusing if there were some way to distinguish between value types and reference types in code.
>> Thank you,
>> swift-evolution mailing list
>> swift-evolution at swift.org
> swift-evolution mailing list
> swift-evolution at swift.org
More information about the swift-evolution