[swift-users] Should I be using more catchless do blocks?
Rien at Balancingrock.nl
Tue Jun 20 00:45:46 CDT 2017
But: Only if it makes the code better.
I think that “understandability engineering” is just as important as “software engineering”. Maybe more so. After all, code that we understand has a better chance of working correctly than code that follows all paradigms but once the developer is gone nobody is able to maintain.
I.e. worry less about idiomatic programming and write more understandable code.
Swift is getting - well maybe it’s past already - the point where an experienced programmer can write code that no newbie has even a chance of understanding. If code blocks help in breaking this trend, go for it.
Project: http://swiftfire.nl - An HTTP(S) web server framework in Swift
> On 19 Jun 2017, at 04:07, Michael Savich via swift-users <swift-users at swift.org> wrote:
> So, something I did not know until recently is that do blocks in Swift are for more than just error handling, they can also be used to tighten scope.
> I'm wondering, why not use a ton of do blocks? Like, if I have a ViewController lifecycle method like viewDidLoad, I could segment it into out a do block for creating subviews, a do block for loading data into them, and a do block for adding them to the view itself. This seems like it would enforce grouping code tightly together.
> Yes I could adopt a functional style of programming, but that has its downsides too, namely reading any functional code involves trawling through a long sequence of function calls. What I'm saying is, do blocks seem like a way to get many of the benefits of functional programming while maintaining the readability of imperative code. (Sorry functional programmers, I promise I love Haskell too!)
> So I guess what I'm saying is… somebody talk me down from this ledge. Is there a reason I shouldn't refactor my projects to be full of do blocks? And can this usage of do really be considered idiomatic Swift? Or will most people reading my code be left wondering where all the try and catch statements are?
> Sent from my iPad
> swift-users mailing list
> swift-users at swift.org
More information about the swift-users