On Wed, Jun 28, 2017 at 8:13 PM, Erica Sadun <[email protected]> wrote:
> > On Jun 28, 2017, at 6:26 PM, Xiaodi Wu <[email protected]> wrote: > > On Wed, Jun 28, 2017 at 5:05 PM, ilya via swift-evolution < > [email protected]> wrote: > >> One could, for example, extend the existing* documentation markup sign* >> *///* to pick up text as force unwrap messages: >> >> `let last = array.last! /// Array guaranteed non-empty` >> > > I did not call this out initially, but I feel like this is an important > point to address: > > In the initial example, repeated here in largely identical form, the > desired comment is "array must be non-empty." In what way does that provide > more information than a bare `!`? > > > That is why I changed it back to my "*guarantee*" version when replying: > > guard !array.isEmpty else { ... } > /* ... */ > let finalElement = array.last !! "Array guaranteed non-empty" > > > The expected unwrap behavior is clear and audited, even when other code > appears between the guard statement and the explained forced unwrap. > > As you point out, it's senseless to annotate a logical assertion known to > be true ("must be non-empty") *unless that annotation enhances the > expression of why and how this otherwise dangerous operation is taking > place*. That explanation forms the mission statement of the `!!` operator. > Sorry, I fail to see how either wording enhances the expression of why this operation is taking place. The entire explanation seems self-evident to me in `!`. > By explaining, the `!!` operator differs from the direct use of `!`. It > explains a fact known to hold true that allows the lhs to safely unwrap. It > provides this in a way that is succinct and readable. It naturally moves > with the line of code it is part of. The adoption of `!!` has already > broadly been integrated into any number idiomatic libraries. Coders have > done so to differentiate an *audited known fact* from the stray `!`, > which may or may not be followed by a comment. > _Every_ use of `!` is an assertion that it is an audited known fact that the operand is not nil. What I'm saying is that, so far in this conversation, I have seen no example where any other known fact on the RHS of your proposed operator is not trivially deducible from the built-in known fact signified by `!` itself. One last point: it is not the mission of document comments to provide any > role beyond annotation. They are not there to guarantee preconditions, > assertions, or any other behavioral contracts. They merely document. > > -- Erica > > > >
_______________________________________________ swift-evolution mailing list [email protected] https://lists.swift.org/mailman/listinfo/swift-evolution
