Harmful GOTOs, Premature Optimizations, and Programming Myths are the Root of all Evil

Harmful GOTOs, Premature Optimizations, and Programming Myths are the Root of all Evil

See: http://videlalvaro.github.io/2015/02/programming-myths.html

This talk is a discussion of the paper Structured Programming with Go To Statements by Donald Knuth, in which some programming myths that populate our industry are reviewed.

Maxims like "Go To Considered Harmful" or "Premature optimization is the root of all evil" are revisited and analyzed in context, both in the paper in which they appeared, and by further comments made by the authors, which are usually ignored.

At the same time a glimpse is given about what was the computer industry back in 1974, the year Knuth's paper was published, in order to better understand the concerns of the author in his paper.

At the end we try to analyze the current state of our industry, specifically around what has been dubbed "Buzzword Oriented Programming", the attitude of judging the merit of technologies based on blog post titles, or the 140 characters of a tweet.

The talk was originally presented at Papers We Love Madrid.

B3eb24dc767e178a2c7d67f1ee1af11f?s=128

Alvaro Videla

February 13, 2015
Tweet

Transcript

  1. Harmful GOTO's, Premature Optimizations, and Programming Myths are The Root

    of all Evil Alvaro Videla
  2. Myths

  3. myth: a widely held but false belief or idea Google

    define
  4. myth: an unproved or false collective belief that is used

    to justify a social institution dictionary.com
  5. The Book of Legendary Lands

  6. What it was that Christopher Columbus tried to demonstrate?

  7. A History of the Life and Voyages of Christopher Columbus

  8. Lactantius - Cosmas Indicopleustes

  9. Do we have similar myths in Computer Science?

  10. Some Myths • No Unit-Tests, no working code • Procedure

    calls are expensive • NoSQL is faster than traditional DBs • 10x Engineers • Servers are cheaper than engineers
  11. In the beginning…

  12. May I ask if there is a reason why you

    prefer using goto instead of function recursion? https://github.com/igorw/retry/issues/3
  13. retry library <?php namespace igorw; class FailingTooHardException extends \Exception {}

    function retry($retries, callable $fn) { beginning: try { return $fn(); } catch (\Exception $e) { if (!$retries) { throw new FailingTooHardException('', 0, $e); } $retries--; goto beginning; } }
  14. retry library <?php namespace igorw; class FailingTooHardException extends \Exception {}

    function retry($retries, callable $fn) { beginning: try { return $fn(); } catch (\Exception $e) { if (!$retries) { throw new FailingTooHardException('', 0, $e); } $retries--; goto beginning; } }
  15. retry library

  16. GOTO flamewar dot gif

  17. Go To Statement Considered Harmful

  18. GOTO still considered harmful?

  19. A case against the goto statement + Niklaus Wirth =

    Go To Statement Considered Harmful
  20. None
  21. Please don't fall into the trap of believing that I

    am terribly dogmatical about [the go to statement]. I have the uncomfortable feeling that others are making a religion out of it, as if the conceptual problems of programming could be solved by a single trick, by a simple form of coding discipline! E. Dijkstra
  22. Please don't fall into the trap of believing that I

    am terribly dogmatical about [the go to statement]. I have the uncomfortable feeling that others are making a religion out of it, as if the conceptual problems of programming could be solved by a single trick, by a simple form of coding discipline! E. Dijkstra
  23. In search of Silver Bullets • Microservices • Testing •

    Agile • Performance Tricks • NoSQL • Message Queues
  24. Beating the CAP Theorem https://www.youtube.com/watch?v=Wp08EmQtP44#t=1273

  25. There is no single development, in either technology or management

    technique, which by itself promises even one order of magnitude [tenfold] improvement within a decade in productivity, in reliability, in simplicity Frederick Brooks Jr No Silver Bullet - http://worrydream.com/refs/Brooks-NoSilverBullet.pdf
  26. Structured programming with go to statements • Introduction • Elimination

    of Go To Statements • Introduction of Go To Statements • Conclusions
  27. Structured programming with go to statements

  28. What year is this paper from?

  29. 1974 http://www.gregwilson.co.uk/tag/muhammad-ali/

  30. http://dl.acm.org/citation.cfm?id=807045&dl=ACM&coll=DL

  31. Logic Programming http://dspace.mit.edu/handle/1721.1/6171 http://dl.acm.org/citation.cfm?doid=155360.155362 1969 1972

  32. http://web.archive.org/web/20120716185629/http://www.bitsavers.org/pdf/dartmouth/BASIC_Oct64.pdf

  33. 1973: Ethernet & UNIX http://www.computerhistory.org/timeline/?year=1973

  34. 1976: Big O Notation http://www.phil.uu.nl/datastructuren/10-11/knuth_big_omicron.pdf

  35. 1976: Big O Notation http://www.phil.uu.nl/datastructuren/10-11/knuth_big_omicron.pdf

  36. 1977: RSA http://www.google.com/patents/US4405829

  37. 1978: Type Polymorphism https://courses.engr.illinois.edu/cs421/sp2013/project/milner-polymorphism.pdf

  38. TL;DR: 1974 • Almost no personal computers • Public Encryption

    a new thing • Structured Programming was all the rage • Abstract Data Types a new thing
  39. low computer resources

  40. “most of the running time in non-IO-bound programs is concentrated

    in about 3% of the source text” D. Knuth
  41. “Experience indicates that nearly everybody has the wrong idea about

    the real bottlenecks in his programs” D. Knuth Computer Programming as an Art - http://dl.acm.org/citation.cfm?id=361612
  42. “we should forget about small efficiencies, say about 97% of

    the time” D. Knuth
  43. “premature optimization is the root of all evil” D. Knuth

  44. “premature optimization is the root of all evil” D. Knuth

    The Godwin Law of Optimization Discussions
  45. “Yet we should not pass up our opportunities in that

    critical 3%. A good programmer will not be lulled into complacency by such reasoning, he will be wise to look carefully at the critical code; but only after that code has been identified” D. Knuth
  46. “Yet we should not pass up our opportunities in that

    critical 3%. A good programmer will not be lulled into complacency by such reasoning, he will be wise to look carefully at the critical code; but only after that code has been identified” D. Knuth
  47. “the universal experience of programmers who have been using measurement

    tools has been that their intuitive guesses fail” D. Knuth
  48. more GOTO elimination with focus on performance and program readability

  49. “My books emphasize efficiency because they deal with algorithms that

    are used repeatedly as building blocks in a large variety of applications” D. Knuth
  50. “We shouldn't merely remove go to statements because it's the

    fashionable thing to do; the presence or absence of go to statements is not really the issue.” D. Knuth
  51. “We shouldn't merely remove go to statements because it's the

    fashionable thing to do; the presence or absence of go to statements is not really the issue.” D. Knuth
  52. “The question is whether we should ban it [GOTO], or

    educate against it” Donald Knuth
  53. Cargo Cult Programming http://c2.com/cgi/wiki?CargoCult

  54. “The biggest problem we have as human beings is that

    we confuse our beliefs with reality” Alan Kay http://www.tele-task.de/archive/video/html5/14029/
  55. How did we arrive to this status?

  56. Pop Culture

  57. “[in the 70s] computing spread out much, much faster than

    educating unsophisticated people can happen” Alan Kay https://queue.acm.org/detail.cfm?id=1039523
  58. Twitter/HackerNews Oriented Programming

  59. http://tinytocs.org/

  60. “Those who cannot remember the past are condemned to repeat

    it" George Santayana https://archive.org/stream/lifeofreasonorph01sant#page/284/mode/2up
  61. https://archive.org/stream/lifeofreasonorph01sant#page/284/mode/2up

  62. History Repeats Itself Agile vs. Thinking Forth http://thinking-forth.sourceforge.net

  63. History Repeats Itself TDD https://arialdomartini.wordpress.com/2012/07/20/you-wont-believe-how-old-tdd-is/ You won’t believe how old

    TDD is vs.
  64. History Repeats Itself offline-first http://www.isi.edu/~johnh/RESEARCH/ucla/#ficus_replication primarily-disconnected vs.

  65. “In 1968, the Communications of the ACM published a text

    of mine under the title "The goto statement considered harmful", which in later years would be most frequently referenced, regrettably, however, often by authors who had seen no more of it than its title” E. Dijkstra https://www.cs.utexas.edu/users/EWD/transcriptions/EWD13xx/EWD1308.html
  66. “In 1968, the Communications of the ACM published a text

    of mine under the title "The goto statement considered harmful", which in later years would be most frequently referenced, regrettably, however, often by authors who had seen no more of it than its title” E. Dijkstra https://www.cs.utexas.edu/users/EWD/transcriptions/EWD13xx/EWD1308.html
  67. Fahreinheit 451

  68. “Classics cut to fit fifteen-minute radio shows, then cut again

    to fill a two-minute book column, winding up at last as a ten- or twelve-line dictionary resume” Fahrenheit 451
  69. Memes

  70. “[…] there has been far too much emphasis on go

    to elimination instead of on the really important issues; people have a natural tendency to set up all easily understood quantitative goal like the abolition of jumps, instead of working directly for a qualitative goal like good program structure” D. Knuth
  71. “[…] there has been far too much emphasis on go

    to elimination instead of on the really important issues; people have a natural tendency to set up all easily understood quantitative goal like the abolition of jumps, instead of working directly for a qualitative goal like good program structure” D. Knuth
  72. “we should strive most of all for a program that

    is easy to understand and almost sure to work” D. Knuth
  73. “we had better see to it that the computer industry

    does not kill computing science” E. Dijkstra https://www.cs.utexas.edu/users/EWD/transcriptions/EWD12xx/EWD1284.html
  74. Thanks Alvaro Videla - @old_sound