Goto Considered Harmful [was Re: Python and the need for speed]

Steve D'Aprano steve+python at pearwood.info
Thu Apr 13 13:43:55 EDT 2017


On Wed, 12 Apr 2017 10:44 am, Nathan Ernst wrote:

> goto is a misunderstood and much misaligned creature. It is a very useful
> feature, but like nearly any programming construct can be abused.

Indeed. The problem is that it is abused far more often than it is used
correctly -- or at least it was, back in the days when people routinely
used GOTO. People don't abuse GOTO much these days only because most
languages don't encourage, or even allow, GOTO.


> Constructs like 'break', 'continue' or 'next' in languages like Python or
> C/C++ are goto's with implied labels.

They are *restricted* and *structured* jumps, which is not the same thing as
an *unrestricted and unstructured* GOTO.

In much the same way that hiring a private security guard is not quite the
same thing as declaring martial law and telling the soldiers they have
carte blanche to shoot to kill for any reason at all.


> As Mikhail said, goto's can be great to break out of nested loops (only a
> handful of languages support named 'breaks').

I have to ask... 

if named breaks are so great, why don't more languages support them?


> People need to stop drinking "X is considered harmful." 

That's one opinion.


> Even Dijkstra 
> later lamented that his "Goto considered harmful" paper was misinterpreted
> and misrepresented as advocating that goto should never be used.

Citation required.

1987 was pretty much the last gasp of the unstructured programming paradigm,
the last time that anyone made a serious case for it. Frank Rubin responded
to Dijkstra's famous letter with a response

"GOTO Considered Harmful Considered Harmful"

Unfortunately, his response was not so much a refutation of Dijkstra, but
the last desperate and failed defence of an all-but-dead programming style.

Dijkstra responded to Rubin in an especially cranky (and rather pedantic and
arrogant manner). You can read his response here:

https://www.cs.utexas.edu/~EWD/transcriptions/EWD10xx/EWD1009.html

Bottom line: Rubin's code was buggy, and the problem he posed could be
solved without GOTO.

More on the history of Dijkstra's letter here:

https://blog.codinghorror.com/id-consider-that-harmful-too/

and a connection to Python:

http://joshuah.scripts.mit.edu/blog/?p=195



> Additionally, I'd recommend everyone read '"Considered Harmful" Essays
> Considered Harmful': http://meyerweb.com/eric/comment/chech.html

The author makes a number of dogmatic claims without offering a shred of
evidence for any of them. He expects us to simply believe on his say-so
alone that "Considered Harmful" essays are counter-productive to their own
cause, a clear and obvious case of "concern trolling" if I've ever seen
one.

His essay is full of weasel words and unsupported opinions masquerading as
facts:

* Considered Harmful essays "often" inflame the debate (how often? 1% 
  of the time or 99% of the time? how do you know?)

* supporters of the opposing view are "more likely" to dig in and 
  defend their position (how much more like? how do you know?)

* Considered Harmful essays have "a strong tendency to alienate neutral
  parties" (how strong? how do you know?)

and he contradicts himself: Considered Harmful essays are "boring cliches"
that nobody bothers to read or pay any attention to.

Strangely enough, despite Considered Harmful being a boring, counter-
productive cliche that harms your own cause, the author Eric Meyer chose to
write one himself. Recognising this contradiction, he tries to pass it off
as a joke.

And what is his cause? To argue against a strawman, that Considered Harmful
essays cannot and do not "engage in reasoned debate". They don't? Says who?
Why can't a paper that draws a firm and opinionated conclusion (as Meyer
himself does) also be reasoned?

Meyer himself doesn't sit on the fence. He argues against Considered Harmful
essays. Not very convincingly, but he does take a position against them.
Why doesn't he follow his own advice, and describe the strengths and
weaknesses of Considered Harmful essays?

So there's one rule for Meyer, and everyone else should write wishy-washy
fence-sitting essays that draw no firm conclusions.

Meyer states that a "benefits and weaknesses" essay will allow people
to "more readily find a compromise solution" without questioning whether or
not a compromise solution is either possible or desirable. For example:

- A language cannot compromise on the question of whether to allow 
  COMEFROM: it either supports that *deliberately awful* language
  misfeature, or it doesn't. 

- Even if a compromise position is *possible*, that doesn't mean that
  one is desirable. Should array indexing start at 0 or 1, or shall
  we compromise with 0.5? 

Meyer implicitly assumes that technical questions are won by "reasoned
debate", which goes against the history of science and technology and in
fact all of human history. Very few questions can be resolved by mere
facts. Rather, they are resolved by *persuasion*, and despite Meyer's
concern-trolling, it does appear that in at least two cases "Considered
Harmful" essays have persuaded people to turn against the dominant
programming paradigm:

- Unstructured GOTOs
- Global variables.

In both cases, the dominant paradigm has turned around almost 180°, and now
the prevailing wisdom is that both GOTO and global variables should be used
as little as possible, if at all.

TL;DR:

Meyer's "Considered Harmful Essays Considered Harmful" essay is hypocritical
junk, and should be considered harmful.



-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.



More information about the Python-list mailing list