Rename 'guard' to 'ensure'

I prefer "guard". A "guard clause" is a term of art and Shawn put it nicely that the "guard" checks that no one passes beside it which fails the check.

"Ensure" implies to me that something will happen that ensures that the condition will hold after that which has quite a different meaning from guarding (e.g. Eiffel has "ensure" clauses for postconditions, i.e. something that is guaranteed to hold after a method has run).

-Thorsten

···

Am 23. Februar 2016 um 09:55 schrieb Radosław Pietruszewski via swift-evolution swift-evolution@swift.org:

I don’t have a problem with “guard”, and I have grown used to it, but I will give you that “ensure” is probably clearer. “ensure this condition is true”, “ensure that I can let foo = bar” — seems easier to conceptualize its meaning from syntax than “guard”…

The only problem I have is that “ensure” exists in a different language I know (Ruby), where it has different meaning.

So… I’m not sure it’s worth changing “guard” now and I probably wouldn’t be for the change, but I also probably wouldn’t argue against it either ;)

— Radek

On 19 Feb 2016, at 22:49, John Flanagan via swift-evolution swift-evolution@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@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution