Upgrade to Pro — share decks privately, control downloads, hide ads and more …

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.

Alvaro Videla

February 13, 2015
Tweet

More Decks by Alvaro Videla

Other Decks in Programming

Transcript

  1. Harmful GOTO's,
    Premature Optimizations,
    and
    Programming Myths are
    The Root of all Evil
    Alvaro Videla

    View Slide

  2. Myths

    View Slide

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

    View Slide

  4. myth: an unproved or false
    collective belief that is used to
    justify a social institution
    dictionary.com

    View Slide

  5. The Book of Legendary Lands

    View Slide

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

    View Slide

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

    View Slide

  8. Lactantius - Cosmas Indicopleustes

    View Slide

  9. Do we have similar myths in
    Computer Science?

    View Slide

  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

    View Slide

  11. In the beginning…

    View Slide

  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

    View Slide

  13. retry library
    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;
    }
    }

    View Slide

  14. retry library
    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;
    }
    }

    View Slide

  15. retry library

    View Slide

  16. GOTO flamewar dot gif

    View Slide

  17. Go To Statement Considered Harmful

    View Slide

  18. GOTO still considered harmful?

    View Slide

  19. A case against the goto statement
    +
    Niklaus Wirth
    =
    Go To Statement Considered Harmful

    View Slide

  20. View Slide

  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

    View Slide

  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

    View Slide

  23. In search of Silver Bullets
    • Microservices
    • Testing
    • Agile
    • Performance Tricks
    • NoSQL
    • Message Queues

    View Slide

  24. Beating the CAP
    Theorem
    https://www.youtube.com/watch?v=Wp08EmQtP44#t=1273

    View Slide

  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

    View Slide

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

    View Slide

  27. Structured programming
    with go to statements

    View Slide

  28. What year is this
    paper from?

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  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

    View Slide

  39. low computer resources

    View Slide

  40. “most of the running time in
    non-IO-bound programs is
    concentrated in about 3% of the
    source text”
    D. Knuth

    View Slide

  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

    View Slide

  42. “we should forget about small
    efficiencies, say about 97% of
    the time”
    D. Knuth

    View Slide

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

    View Slide

  44. “premature optimization is the
    root of all evil”
    D. Knuth
    The Godwin Law of Optimization Discussions

    View Slide

  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

    View Slide

  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

    View Slide

  47. “the universal experience of
    programmers who have been using
    measurement tools has been that their
    intuitive guesses fail”
    D. Knuth

    View Slide

  48. more GOTO elimination
    with focus on performance
    and program readability

    View Slide

  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

    View Slide

  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

    View Slide

  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

    View Slide

  52. “The question is whether we
    should ban it [GOTO], or
    educate against it”
    Donald Knuth

    View Slide

  53. Cargo Cult Programming
    http://c2.com/cgi/wiki?CargoCult

    View Slide

  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/

    View Slide

  55. How did we arrive to this status?

    View Slide

  56. Pop Culture

    View Slide

  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

    View Slide

  58. Twitter/HackerNews
    Oriented Programming

    View Slide

  59. http://tinytocs.org/

    View Slide

  60. “Those who cannot remember
    the past are condemned to
    repeat it"
    George Santayana
    https://archive.org/stream/lifeofreasonorph01sant#page/284/mode/2up

    View Slide

  61. https://archive.org/stream/lifeofreasonorph01sant#page/284/mode/2up

    View Slide

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

    View Slide

  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.

    View Slide

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

    View Slide

  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

    View Slide

  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

    View Slide

  67. Fahreinheit 451

    View Slide

  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

    View Slide

  69. Memes

    View Slide

  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

    View Slide

  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

    View Slide

  72. “we should strive most of all for a
    program that is easy to understand
    and almost sure to work”
    D. Knuth

    View Slide

  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

    View Slide

  74. Thanks
    Alvaro Videla - @old_sound

    View Slide