ExecutorService - goto in disguise?

Brian Goetz brian.goetz at oracle.com
Mon May 23 16:57:28 UTC 2022


> I'd like to know your opinion on the question from the subject - do you
> think it's justified even to make the comparison between the
> ExecutorService and goto?

I would not argue with the analogy, but I probably wouldn't be so quick 
to make it, either.  And the reason is: it probably sheds more heat than 
light.  After all, we all "know" that goto is intrinsically terrible, 
right?  So comparing something to goto is dramatic, but doesn't really 
help you understand why it is wrong, or how to do better.  (And, 
instruction sets all include goto, so it's clearly OK at some level.)

I prefer to explain this in terms of the kinds of problems that just 
never happen when you follow the structured discipline.  The reason for 
"goto considered harmful" is the effect it has on the reasoning about 
code.  If any line can jump to any other line (and this isn't even goto 
any more, it's goto plus line numbers), then we cannot reason about the 
state of a program at any given line except by analyzing every line of 
the program.  Similarly, structure concurrency enables you to reason 
confidently about "when I get here, this has happened", without 
analyzing the whole program.

Turning global analyses into local ones is at the core of many 
programming disciplines; this is why encapsulation and modularity 
works.  Local reasoning is both more reliable and scales better.



More information about the loom-dev mailing list