Re: [swift-evolution] [Idea] return if / return unless

2016-08-05 Thread Julian Dunskus via swift-evolution
I don’t agree with that. To me, everything between return and if (including the return itself) only being executed if the condition is true seems like the logical way of interpreting that syntax. I do, however, see how people skimming through code might be confused, but a return with code after

Re: [swift-evolution] [Idea] return if / return unless

2016-08-04 Thread Julian Dunskus via swift-evolution
On 05 Aug 2016, at 01:24, Brent Royal-Gordon wrote: > >> On Aug 4, 2016, at 6:38 AM, Julian Dunskus via swift-evolution >> wrote: >> >> return nil unless let thing = things[index] > > On the `unless` part, at least, see the "Rename guard to unless" section in > Commonly Rejected Changes: >

Re: [swift-evolution] [Idea] return if / return unless

2016-08-04 Thread Dave Abrahams via swift-evolution
on Thu Aug 04 2016, Kurt Werle wrote: > Why would you do this just for return statements? Why not do postfix > conditionals for all statements (like ruby)? > > I've always liked postfix conditionals, but not enough to suggest them. -1 from me. Postfix conditionals are easily mistaken for unco

Re: [swift-evolution] [Idea] return if / return unless

2016-08-04 Thread Brent Royal-Gordon via swift-evolution
> On Aug 4, 2016, at 6:38 AM, Julian Dunskus via swift-evolution > wrote: > > return nil unless let thing = things[index] On the `unless` part, at least, see the "Rename guard to unless" section in Commonly Rejected Changes:

Re: [swift-evolution] [Idea] return if / return unless

2016-08-04 Thread Julian Dunskus via swift-evolution
Having postfix conditionals for return would be a lot easier to implement than having them everywhere, because you just need to watch for an if or unless after the return. Of course they might come in handy elsewhere, and may even solve the ever-present problem of the unintuitive ternary operato

Re: [swift-evolution] [Idea] return if / return unless

2016-08-04 Thread David Rönnqvist via swift-evolution
One complication with allowing postfix conditionals for all statements is that it often needs to have an else clause as well (like the ternary operator “?:"). For example, what’s the type of “x” below? let x = 5 if someCriteria() And is “y” initialized or not? let y: Int y = 42 if someCriteria

Re: [swift-evolution] [Idea] return if / return unless

2016-08-04 Thread Kurt Werle via swift-evolution
Why would you do this just for return statements? Why not do postfix conditionals for all statements (like ruby)? I've always liked postfix conditionals, but not enough to suggest them. Mostly I'm curious about limiting the scope to return statements. On Thu, Aug 4, 2016 at 7:31 AM, Christian Ki

Re: [swift-evolution] [Idea] return if / return unless

2016-08-04 Thread Christian Kienle via swift-evolution
+1 2016-08-04 15:38 GMT+02:00 Julian Dunskus via swift-evolution < swift-evolution@swift.org>: > How often have you written something like the following? > > ` > if indexPath.row == 0 { return } > > guard let thing = things[index] else { return nil } > ` > > I propose adding some syntactic sugar

[swift-evolution] [Idea] return if / return unless

2016-08-04 Thread Julian Dunskus via swift-evolution
How often have you written something like the following? ` if indexPath.row == 0 { return } guard let thing = things[index] else { return nil } ` I propose adding some syntactic sugar to make such statements more readable and simple to write: ` return if indexPath.row == 0 return nil unless l