[swift-evolution] Rename 'guard' to 'ensure'

Dave Abrahams dabrahams at apple.com
Mon Feb 22 12:15:14 CST 2016


on Mon Feb 22 2016, Erica Sadun <swift-evolution at swift.org> wrote:

>> " a vision of a little guard standing at his guard post checking papers"
>
> Raises hand. Me too. I like my little guard.
>
> On the other hand, I'd love if assert/precondition would be combined
> into a single call, with an optional `forReleaseBuild:` arg (better
> named) that defaults to false.

I really don't want to do that.  Assert and precondition have different
use-cases, and I don't want people to ask “do I want this on in a
release build?” (which is a hard decision to make correctly and
consistently) when they write them.  I want them to ask, “Am I checking
whether this method is being called correctly or is this just a
self-sanity check?”

>> On Feb 22, 2016, at 10:07 AM, Shawn Erickson via swift-evolution
>> <swift-evolution at swift.org> wrote:
>> 
>> Ensure(TM) ...has a little much sugar for my wants in a drink
>> 
>> I get and like the suggestion from a grammar pov however guard is a
>> little more forceful in terminology which aligns with the fact that
>> you cannot proceed past the guard unless the condition is met. (I
>> have a vision of a little guard standing at his guard post checking
>> papers)
>> 
>> -Shawn
>> 
>> On Mon, Feb 22, 2016 at 9:01 AM John Flanagan via swift-evolution
>> <swift-evolution at swift.org
>> <mailto:swift-evolution at swift.org>>
>> wrote:
>> The functionality of ‘guard’ is great and this proposal has nothing
>> to do with changing that. The only suggestion is that the word
>> ‘ensure’ would better communicate what a ‘guard’ statement does to
>> those encountering it for the first time and would make code more
>> readable in general.
>> 
>> Example:
>> 
>> ensure foo != nil else {
>>    return;
>> }
>> 
>> -John
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution at swift.org
>> <mailto:swift-evolution at swift.org>
>> https://lists.swift.org/mailman/listinfo/swift-evolution <https://lists.swift.org/mailman/listinfo/swift-evolution>
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution at swift.org
>> https://lists.swift.org/mailman/listinfo/swift-evolution
>
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution

-- 
-Dave



More information about the swift-evolution mailing list