<div dir="ltr">What is "guard"? why its the opposite to "if"!<div><br></div><div>So in other languages what have they called this, well in Ruby they called it "unless" which I feel is a much clearer form of intent and lower barrier of entry for a user. See this code.</div><div><br></div><div>guard name != nil else {</div><div> fatalError("Please enter a name")</div><div>}</div><div><br></div><div>What does that actually say if you look at it from a linguistic point of view, "guard that name doesn't equal nil otherwise fail", that feels very obtuse. </div><div><br></div><div>With my proposal the syntax could become this:</div><div><br></div><div>unless name != nil {</div><div> fatalError("Please enter a name")</div><div>}</div><div><br></div><div>This now reads as "unless name doesn't equal nil then fail" which I think is a much clearer syntax. I think this would be a great change for Swift 3. For me I think this is more friendly for beginners.</div><div><br></div><div>It would support the same structure as an if block:</div><div><br></div><div>unless name != nil {</div><div>}</div><div>else</div><div>{</div><div>}</div><div><br></div><div>Going forward it would allow us to be more flexible if we added inline if/unless statement, as in Ruby.</div><div><br></div><div>callThisMethod() if age > 0</div><div>throwThisError() unless age <= 0</div><div><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div><span style="font-size:16px;line-height:19.2px"></span><span style="font-size:12.8px"> Wizard</span><br></div><div><a href="mailto:james@supmenow.com" target="_blank">james@supmenow.com</a></div><div>+44 7523 279 698</div></div></div></div></div></div>
</div></div>