use standard syntax instead of "do" and "repeat"

(Andrew Duncan) #1

func recognizeHandler() throws {
   try {
       accept(.on) // .on is an enum tag for the token for the ‘on’ keyword.
       recognizeName() // Later Visitor pass checks that names match.

Indeed. Also, FWIW, I’d argue that maybe the root problem here is that this code should not be using Swift’s error handling constructs in the first place. An enum (or other approach) may be more appropriate. Swift’s error handling design is intentionally driven by the idea that you shouldn’t use it if “everything throws” - in this situation, the sugar benefits of error handling are intentionally outweighed by the weight of the try keywords everywhere. This is meant to force the balance over to using more manual techniques.


Quite so. That is what prompted an earlier topic about guarding on Optionals:

In fact, I did go with a construct like

   let r = returnsSucceedOrFailEnum()
   guard case let .Succeed(node) = r else { return r } // Back down the call stack.
   // Safe to use node; r now irrelevant but in scope.

Alas, my LOC soared. More code, more bugs.

Apart from considerations of propriety, are there performance up/downsides to either approach?


Joining Old Orphaned Posts to the Main Threads