[swift-evolution] Add unless/if single line syntax

James Campbell james at supmenow.com
Sat Dec 12 10:14:11 CST 2015


For what it's worth. If swift is about clarity, then guard is quite an
obscure keyword.

On Sat, Dec 12, 2015 at 4:12 PM, Matthew Johnson via swift-evolution <
swift-evolution at swift.org> wrote:

> I’ve written enough Ruby code to appreciate these keywords and believe
> they are worth adding the keywords.  I know others don’t agree and that the
> Swift team considered this earlier and did not add them for the exact
> reason you stated.
>
> I think it would be good to get a read on where the community stands.  I’m
> not sure which opinion is in the majority.
>
> On Dec 12, 2015, at 10:08 AM, Al Skipp <al_skipp at fastmail.fm> wrote:
>
> If at all possible I think it’s best to avoid adding keywords to the
> language. Instead of ‘unless', you could do:
>
> public func not(bool: Bool) -> Bool { return !bool }
>
> if not(condition) { print("condition was false") }
>
> Not terrible ¯\_(ツ)_/¯
>
>
> On 12 Dec 2015, at 15:48, Matthew Johnson via swift-evolution <
> swift-evolution at swift.org> wrote:
>
> I’m not sure about the single line aspect of this proposal, but I am a big
> proponent of “unless” and “until” as complements to “if” and “while”.  They
> greatly improve readability over "if !(expression)” and “while
> !(expression)” IMHO.
>
> On Dec 12, 2015, at 9:45 AM, Arthur Ariel Sabintsev via swift-evolution <
> swift-evolution at swift.org> wrote:
>
> For your specific example, I'd 100% use the guard statement. It achieves
> the same result.
>
> -1 from me.
> On Sat, Dec 12, 2015 at 9:43 AM J. Cheyo Jimenez via swift-evolution <
> swift-evolution at swift.org> wrote:
>
>> -1 from me.  I think I would rather have an if-then expression that would
>> handle both False and True cases.
>>
>> https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20151207/001944.html
>>
>> Also, in most cases I feel that guard would be a better choice.
>>
>>
>>
>> On Sat, Dec 12, 2015 at 5:39 AM, James Campbell via swift-evolution <
>> swift-evolution at swift.org> wrote:
>>
>>> I propose adding the unless and if statements from ruby.
>>>
>>> Return false if james = nil
>>>
>>> This returns false if the variable James is nil
>>> . This line does it unless james is nil:
>>>
>>> Return false unless james = nil
>>>
>>> This has been really handy when working in ruby, reduces lines and
>>> pyramids of doom
>>>
>>> Sent from my iPhone
>>> _______________________________________________
>>> 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
>>
>  _______________________________________________
> 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
>
>
>
>
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
>
>


-- 
 Wizard
james at supmenow.com
+44 7523 279 698
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151212/93db7362/attachment.html>


More information about the swift-evolution mailing list