<div dir="ltr">–1. This would make reading and maintaining code appreciably harder for a trivial reduction in character count when writing code. </div><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div>Riley</div></div></div></div></div></div>
<br><div class="gmail_quote">On 23 February 2016 at 23:06, Darko Damjanovic via swift-evolution <span dir="ltr"><<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">In the current Swift version the compiler is warning me if a variable is never written to and therefore should be a "let" constant. So now the compiler knows best if "let" or "var" should be applied. During writing code I experience repetitive hints about using "let" or "var" so why do I have to declare it all the time by myself if the compiler anyway knows best?<br>
<br>
My proposal would be to make the declaration of "let" and "var" optional.<br>
<br>
Example:<br>
x = 0 // <- implicitly declared as "var x" because later was written to, no need to declare it manually<br>
x = 5<br>
<br>
Example:<br>
y = 0 // <- implicitly declared as "let y" because later was not written to<br>
print(y)<br>
<br>
Example Optional Binding:<br>
if index = myArray.indexOf("A") {<br>
print(index) // here it's clear that index can be "let index"<br>
}<br>
<br>
etc...<br>
<br>
This would _not_ mean to disallow or remove the "var and "let" mutability declarations - just to make them optional. If I still want to write it to make it clear just by reading thru the code then this is ok. But I can omit "var and "let" if I want - why bother about it at all if I can go sure that the compiler is already doing the best?<br>
<br>
Another option (if this is "too much" change) would be to just make "let" optional and "var" still should be explicitly written. So "let" would be the default and if I want mutability I have explicitly declare it as "var". This is already the rule for function parameters.<br>
<br>
Kind regards,<br>
Darko Damjanovic-Lichtfuss<br>
<br>
<br>
<br>
<br>
<br>
_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
</blockquote></div><br></div>