I'm confused about 'defer'. Not the purpose, the chosen syntax. 

func confusing() {
    print("1")
    defer { print("2") }
    print("3")
}

Produces 1,3,2. Trying to describe what is happening here is non-trivial... it 
runs line 1, then we put line 2 on a stack, then line three runs, then we pop 
the stack... what?! And stepping through it in the debugger... ugh.

Unless I missed something obvious, wouldn't placing "code that always has to 
run at the end" actually *at the end* not make more sense? Like this...

func clear() {
    print("1")
    print("3")

    always { print("2") }
}

Not only is the code clearly expressing its intent, the actual execution is 
following the source.


_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to