|
|
|
|
|
by jonhohle
599 days ago
|
|
I usually find the opposite (personally). Get rid of all the exceptional cases and error handling up front like you have in the first example and then spend the remaining body of the function doing the main work of that function. It’s not so much indentation that’s an issue, but coupling control flow with errors and exceptions. Swift does a nice job with `guard` statements that basically bake this in at the language level - a condition succeeds or you must return or throw. If that control flow is part of business logic, I don’t think there’s any issue with your second example. That’s what it’s there for. |
|