<div dir="ltr">Should we add this to the list of things requested that will be rejected ?</div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jan 6, 2016 at 10:58 AM, Greg Parker <span dir="ltr"><<a href="mailto:gparker@apple.com" target="_blank">gparker@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=""><br>
> On Jan 6, 2016, at 2:09 AM, James Campbell via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:<br>
><br>
> What is "guard"? why its the opposite to "if"!<br>
><br>
> 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.<br>
><br>
> guard name != nil else {<br>
> fatalError("Please enter a name")<br>
> }<br>
><br>
> 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.<br>
><br>
> With my proposal the syntax could become this:<br>
><br>
> unless name != nil {<br>
> fatalError("Please enter a name")<br>
> }<br>
><br>
> 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.<br>
><br>
> It would support the same structure as an if block:<br>
><br>
> unless name != nil {<br>
> }<br>
> else<br>
> {<br>
> }<br>
><br>
> Going forward it would allow us to be more flexible if we added inline if/unless statement, as in Ruby.<br>
><br>
> callThisMethod() if age > 0<br>
> throwThisError() unless age <= 0<br>
<br>
</span>`guard` is not the opposite of `if`. `guard` has effects that `if` does not. We deliberately chose not to provide syntax that was identical to `if not X`.<br>
<br>
History: The very first proposal of this feature was called `unless`. Fifty-odd messages of discussion later it was called `require`, in part because we did not want to match the `if not` constructs seen in languages like Perl and Ruby. That name was still controversial. A few weeks later it was changed to `guard..else` to general acclaim because the intended use is commonly known as a "guard clause".<br>
<span class="HOEnZb"><font color="#888888"><br>
<br>
--<br>
Greg Parker <a href="mailto:gparker@apple.com">gparker@apple.com</a> Runtime Wrangler<br>
<br>
<br>
</font></span></blockquote></div><br><br clear="all"><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>