At this point in Swift's evolution, source-breaking changes to the language require strong motivation. We can't really entertain superficial keyword changes like this without overwhelming evidence that the existing syntax is problematic in practice. `guard` has precedent in functional languages, for instance in Haskell where the `guard` function is idiomatically used as part of monadic `do`-notation computations, and has the same positive condition semantics in those languages.
-Joe > On Oct 25, 2016, at 9:38 AM, Jay Abbott via swift-evolution > <[email protected]> wrote: > > I mentioned this in passing on a different thread. Although it caused some > slight confusion when I first learned the 'guard' keyword, it was easy to > overcome and I didn't think the issue was strong enough to warrant a change. > However, after reading the other discussion on that thread (around the > possibility of a 'matches' keyword and how code is "read out" or "internally > verbalised"), and seeing how passionate everyone here is about Swift, I'm > thinking that maybe it should be changed. > > The issue is that in English, 'guard' has an inverted logical connotation to > how it is used in Swift. For example, take this sentence: > > "In some functions it's a good idea is to put some checks in place, in order > to guard against invalid input values." > > Swift's 'guard' keyword is to guard against invalid values. > Or to put it another way, to ensure that we have valid values. > > However, the way it reads in Swift, we guard that we have valid values. > > I fully understand and agree that it's better to state the true condition for > valid values here, using else to perform a contingency. And I understand why > the word 'guard' was picked (given the above example sentence). I just think > that 'ensure' would be better. > > ensure x > 0 else { > return > } > > ensure camp.isSafe else { > runForTheHills() > } > > ensure let thingy = object as? Thingy else { > return ExamineThingyResult.NotAThingy > } > > As I said, I thought it was too small a niggle to worry about, but seeing how > people on here care so much about making Swift better, and the willingness to > change things, I thought I'd suggest it. Although it would be a breaking > change, the code changes are easy. > > So what do people think? In particular it would be interesting to hear from > non-native English speakers on this, did 'guard' confuse you or did 'guard' > cause your understanding of the English word to be confused? > > _______________________________________________ > swift-evolution mailing list > [email protected] > https://lists.swift.org/mailman/listinfo/swift-evolution _______________________________________________ swift-evolution mailing list [email protected] https://lists.swift.org/mailman/listinfo/swift-evolution
