(Sorry if you get this email twice, I realized I first sent it from an email
address that is not the one I used to subscribe to this list)
Not only that, but placing defer at the end of a scope, where any other code
may never get executed if there’s an early return, kind of violates the whole
concept of control flow.
func f() throws {
let o = file(path: "")
o.openFile()
do {
try o.write(self.data)
}
print("success")
always { o.close() }
}
What happens if o.write fails? Going with always would imply that we either…
A) put the `always` in every possible place the scope might exit, defeating the
whole purpose of defer/always. Maury, I’m assuming you’re not actually
suggesting that, which would leave: B) if the main scope of the function exits
at any point, drop down to the `always` at the end of the scope and execute it.
But then, what about the surrounding code at the end of the main scope? Like I
said, I think this would violate the whole concept of control flow by
cherry-picking a specific type of command that is always executed within a
scope, even if that command is in some place the control flow doesn’t reach.
Unless I’m misinterpreting something (let me know if I am) this seems less
intuitive than `defer` was to begin with.
-Robert
> On Jan 2, 2016, at 3:17 PM, Dennis Lysenko via swift-evolution
> <[email protected]> wrote:
>
> Deferring at the end of the function removes the ability to defer actions on
> variables introduced in an inner scope.
>
>
> On Sat, Jan 2, 2016, 1:57 PM Tino Heth via swift-evolution
> <[email protected] <mailto:[email protected]>> wrote:
> I have the terrible feeling something is wrong with my posts so that they get
> caught by spamfilters or similar…
>
> But as others stated as well:
> defer has a use case that is a little bit different from what you want to
> archive.
>
> > Why not use a solution that is widely used and better?
> I'm curious:
> Which languages have this "always" construct?
> _______________________________________________
> swift-evolution mailing list
> [email protected] <mailto:[email protected]>
> https://lists.swift.org/mailman/listinfo/swift-evolution
> <https://lists.swift.org/mailman/listinfo/swift-evolution>
> _______________________________________________
> 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