[TUHS] I can't drive 55: "GOTO considered harmful" 55th anniversary

segaloco via TUHS tuhs at tuhs.org
Sat Mar 11 05:35:50 AEST 2023


That's a good point about the specifics, there's no one-size-fits-all error condition that describes every possible exceptional circumstance, so how could there be one singular best practice for handling the abstract concept of an "error".

Plus, given one person's error is another person's business logic sometimes...if we can't agree on what an error is, how can a computer be expected to :P

- Matt G.

------- Original Message -------
On Friday, March 10th, 2023 at 11:04 AM, Dan Cross <crossd at gmail.com> wrote:


> On Fri, Mar 10, 2023 at 1:55 PM Ron Natalie ron at ronnatalie.com wrote:
> 
> > That’s my point. Both break structure.
> > 
> > Just hinding the break with some construct that isn’t “goto” doesn’t
> > make it acceptable.
> 
> 
> The alternative is often worse, though. I'd take a well-aimed goto or
> a nested break over a bunch of conditionals in the bodies of loops any
> day, both in terms of readability and performance.
> 
> That said, I'm not a huge fan of the `goto fail;` pattern. Apple had a
> pretty major bug with that, and I find that many, many times it can be
> replaced with a restructuring of the code. For example, perhaps do
> your allocation, call a function and capture the return value (passing
> the allocated resources as arguments), and then de-allocate and return
> the cached return value. Let the compiler optimize it.
> 
> As an experiment, I rewrote the Apple bug code (which was open source)
> to do that and it was cleaner and simpler than the original. Someone I
> showed it to said, "but what, are you going to do that for every
> function that can fail?" Well no, but generally you don't have to; we
> fixate too much on the general problem and ignore the specifics.
> 
> - Dan C.


More information about the TUHS mailing list