Today, I wrote a fortune shell script to demonstrate how Swift could be used for scripting without having to build an entire application. I ended up using cascading let statements in a way I haven’t really to date. When 1.2 introduced these to “avoid the pyramid of doom”, I didn’t quite see how well they created a readable stack of steps.
What’s particularly interesting to me is how these steps short-cut the normal call/test for error/respond-to-error Cocoa-y flow of things. If any step fails, everything fails, leading to a central fail point (return nil). Explaining what went wrong isn’t easy to detail any further unless all the calls subscribe to an NSError** pattern.
The if-statement feels a little like an overstuffed turkey, which is not necessarily a good feeling when writing code. I’m still trying to decide if I love this or not.