<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Jun 8, 2016, at 11:54 AM, Антон Жилин via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">The difference between &nbsp;nil &nbsp;and &nbsp;.none &nbsp;is that the former is more "generic" than the latter.<div class=""><br class=""><div class="">NilLiteralConvertible protocol expresses types that can contain "null" as legal values. `nil` does not have a type, it's just a token that is casted to whatever NilLiteralConvertible type is expected. It is used in JSON libraries, for example:</div></div><div class=""><br class=""></div><div class="">let tree: JSON = ["name": "Alex", "age": 20, "email": nil]</div><div class=""><br class=""></div><div class="">Here, nil would be inferred to have our custom JSON type.</div><div class="">The same example with &nbsp;none &nbsp;would look a bit more weird:</div><div class=""><br class=""></div><div class="">let tree: JSON = ["name": "Alex", "age": 20, "email": none]<br class=""></div><div class=""><br class=""></div><div class="">None of what type? Of String? Of Int? Of JSON? There are no optionals in this code. And a "null"&nbsp;present in JSON is different than no JSON in Swift.</div></div></div></blockquote><div><br class=""></div><div>I have seen an example like this several times. In every case, I find the “none” one to be clearer. Why? Because it indicates that there is no email. nil to me looks like it could be a null pointer that could have bad consequences when accessed</div><div><br class=""></div><div>nil is special word that we are use to from other languages. It *sounds* natural in this case because it is familiar.</div><div><br class=""></div><div>I am not familiar with JSON libraries, but I don’t think that should guide the direction on which way to go.</div><div><br class=""></div><div>Also,<b class=""> I am more specifically referring to nil with the use of optionals, not NilLiteralConvertible:</b></div><div><br class=""></div><div>let i: Int? = nil</div><div>let i: Int? = .none</div><div><br class=""></div><div>There are two ways to write the same thing with one being far clearer in my opinion. What does nil mean in this case? It precisely represents Optional&lt;Int&gt;.none making it somewhat redundant and surprising considering how nil is used in other languages.&nbsp;</div><div><br class=""></div><div>More specifically, what is nil? 0? A pointer? A representation of nothing (again implying none!)?</div><div><br class=""></div><div>I am very curious how new programmers coming to Swift as their first language would react to using nil in other languages. I think they would be very surprised.</div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class=""><br class=""></div><div class="">Optional is the most significant example of NilLiteralConvertible, but there are other users that would suffer from renaming. We could remove NilLiteralConvertible at all, but look at the example in this case:</div><div class=""><br class=""></div><div class="">let tree: JSON = ["name": "Alex", "age": 20, "email": JSON.nullValue]<br class=""></div></div></div></blockquote><div><br class=""></div><div>This is somewhat more explicit and clearer in my opinion. Again, I am not familiar with JSON libraries so this could be why it looks clearer to me.</div><div><br class=""></div><div>From your response, I see the words “nil”, “null”, and “none”. Doesn’t this seem a little excessive and maybe confusing for people?</div><div><br class=""></div><div>Thanks,</div><div>Brandon</div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class=""><br class=""></div><div class="">That would hurt immersion of the DSL.</div><div class=""><br class=""></div><div class="">I think some Core team member told that they intentionally keep two ways of handling Optional: one using nil, and the other treating it like other enums.</div><div class=""><br class=""></div><div class="">- Anton</div></div>
_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></blockquote></div><br class=""></body></html>