Rex Kerr
1 min readFeb 11, 2025

--

So we have magic behavior-changing statements randomly inside our code with no block or anything to tell us what is going on?

And this is somehow better than the loan pattern, which is well-established in a bunch of languages? Or sum types with success and error branches, also well-established in a bunch of languages? Or RAII, which guarantees cleanup in every case, not just in the case where you managed to remember to do it?

I think not!

The advantage is that it's simple and flexible. It's not the best way to solve the problem; far from it. But it is a simple and flexible way to solve the problem, and sometimes that's what you want.

And the use of goto? Well, one of the most important cases is retrying earlier code after making some changes to state, and this doesn't help that at all. Rather than an awful mess of while loops with dummy variables that you have to keep track of, you simply detect an issue, make a fix, and jump back to where you need to be to retry it. Easy! Dangerous! But easy! And not addressed by defer or errdefer at all.

--

--

Rex Kerr
Rex Kerr

Written by Rex Kerr

One who rejoices when everything is made as simple as possible, but no simpler. Sayer of things that may be wrong, but not so bad that they're not even wrong.

Responses (3)