[swift-evolution] Reconsidering SE-0003 Removing var from Function Parameters and Pattern Matching

Dany St-Amant dsa.mls at icloud.com
Sat Jan 30 21:45:12 CST 2016


> Le 30 janv. 2016 à 20:50, Howard Lovatt via swift-evolution <swift-evolution at swift.org> a écrit :
> 
> +1 for `bind`. I dislike the use of the same keyword for two different purposes. Also `if let x = x` is confusing for beginners (by beginners I mean beginners to Swift not to programming) since:
> 
>   1. `let x = x` is, outside of binding, an error. 
>   2. Beginners quite rightly say "`x` already equals `x`!".

For me, the keyword bind should not be limited to this kind of nil check. but act a bit like an alias. Unfortunately, I cannot come up with nice Swift example; and not sure yet if an aliasing concept is applicable to Swift. For example in C, it is quite common to do:

myStructType *myStruct = (*myStruct) someVoidPtr;

Or you can do

myStructType *myStruct = &nested.structs.array[index];

So that you can use the short name for the heavy work. For read-only operation, the let keyword can be used in that way; but there’s seems to be no easy way if one want to mutate the original data (you are welcome to prove me wrong, my Swiftness is limited)

On the "let x = x" being illegal outside binding, maybe we should make it illegal too for optional binding, especially that the optional binding with var will be reintroduced. This shadowing make it simple when you change your variable from non-optional to optional, as you just wrap the code in the "if let x=x", re-indent the code and voilà; if prohibited one will need to rename all the x by y inside the re-indented code. But such shadowing   as its detractor, after all troubles hide in the shadow. But I’ll leave this to be discuss in another thread if someone fells like starting a long and painful discussion, with three battle camps: should allow let x=x, should be an error, should be a warning.

Dany

> On Friday, 29 January 2016, Joe Groff via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
> 
> > On Jan 28, 2016, at 10:05 AM, Erica Sadun <erica at ericasadun.com <javascript:;>> wrote:
> >
> > Do you realize how much confusion it would save if Swift just went with
> >
> > if bind foo = bar {...}
> >
> > with let semantics?
> 
> I don't see how changing the keyword changes anything, no.
> 
> -Joe
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org <javascript:;>
> https://lists.swift.org/mailman/listinfo/swift-evolution <https://lists.swift.org/mailman/listinfo/swift-evolution>
> 
> 
> -- 
>   -- Howard.
> 
> _______________________________________________
> 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/20160130/6e35f273/attachment.html>


More information about the swift-evolution mailing list