<div dir="ltr">I think you should explore the direction of removing NilLiteralConvertible entirely, together with nil. My example could instead use:<div><br></div><div>let tree: JSON = ["name": "Alex", "age": 20, "email": .null]<br></div><div><br></div><div>Rationale would be that when nil was added to the language, enum constructors could not omit their types. Now there is no reason for nil, especially that it makes developers use only approximately suitable terms.</div><div><br></div><div>- Anton</div></div><div class="gmail_extra"><br><div class="gmail_quote">2016-06-08 19:12 GMT+03:00 Brandon Knope <span dir="ltr"><<a href="mailto:bknope@me.com" target="_blank">bknope@me.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><br><div><span class=""><blockquote type="cite"><div>On Jun 8, 2016, at 11:54 AM, Антон Жилин via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> wrote:</div><br><div><div dir="ltr">The difference between nil and .none is that the former is more "generic" than the latter.<div><br><div>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><br></div><div>let tree: JSON = ["name": "Alex", "age": 20, "email": nil]</div><div><br></div><div>Here, nil would be inferred to have our custom JSON type.</div><div>The same example with none would look a bit more weird:</div><div><br></div><div>let tree: JSON = ["name": "Alex", "age": 20, "email": none]<br></div><div><br></div><div>None of what type? Of String? Of Int? Of JSON? There are no optionals in this code. And a "null" present in JSON is different than no JSON in Swift.</div></div></div></blockquote><div><br></div></span><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></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></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></div><div>Also,<b> I am more specifically referring to nil with the use of optionals, not NilLiteralConvertible:</b></div><div><br></div><div>let i: Int? = nil</div><div>let i: Int? = .none</div><div><br></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<Int>.none making it somewhat redundant and surprising considering how nil is used in other languages. </div><div><br></div><div>More specifically, what is nil? 0? A pointer? A representation of nothing (again implying none!)?</div><div><br></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><span class=""><br><blockquote type="cite"><div><div dir="ltr"><div><br></div><div>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><br></div><div>let tree: JSON = ["name": "Alex", "age": 20, "email": JSON.nullValue]<br></div></div></div></blockquote><div><br></div></span><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></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></div><div>Thanks,</div><div>Brandon</div><br><blockquote type="cite"><div><span class=""><div dir="ltr"><div><br></div><div>That would hurt immersion of the DSL.</div><div><br></div><div>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><br></div><div>- Anton</div></div></span>
_______________________________________________<br>swift-evolution mailing list<br><a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br></div></blockquote></div><br></div></blockquote></div><br></div>