$30 off During Our Annual Pro Sale. View Details »

Debugging Zen (Lone Star PHP 2015)

Debugging Zen (Lone Star PHP 2015)

Debugging is one of those skills that developers have the hardest time exercising and is also one of the most difficult to teach. It is both a scientific discipline and an art. It often requires you to reach beyond analytical thinking to rely upon your own intuition in order to solve a problem. In this talk, we’ll examine how intuition plays a crucial role in debugging software. You’ll leave with practical pointers on how to tap into intuition as part of your debugging habits and how to combine it with analytical processes to be a better developer.

Ben Ramsey
PRO

April 18, 2015
Tweet

More Decks by Ben Ramsey

Other Decks in Programming

Transcript

  1. Debugging
    Zen
    Ben Ramsey

    View Slide

  2. Not Zend!

    View Slide

  3. HI, I’M BEN.
    I’m a web craftsman, author,
    and speaker. I build a platform
    for professional photographers
    at ShootProof. I enjoy APIs, open
    source software, organizing user
    groups, good beer, and
    spending time with my family.
    Nashville, TN is my home.
    virtPHP
    ✤ Books
    ✤ Zend PHP Certification
    Study Guide
    ✤ PHP 5 Unleashed
    ✤ Nashville PHP & Atlanta PHP
    ✤ array_column()
    ✤ rhumsaa/uuid library
    ✤ virtPHP
    ✤ PHP League OAuth 2.0 Client

    View Slide

  4. View Slide

  5. Debugging
    Zen?

    View Slide

  6. View Slide

  7. View Slide

  8. Debugging

    View Slide

  9. To search for and eliminate
    malfunctioning elements or errors in
    something, especially a computer
    program or machinery.
    debug
    /diːˈbʌɡ/

    View Slide

  10. Zen

    View Slide

  11. (colloquial) Extremely relaxed and
    collected.
    (informal) A philosophy of calm,
    reminiscent of that of the Buddhist
    denomination.
    zen
    /zɛn/

    View Slide

  12. Just What Is
    Intuition?

    View Slide

  13. “Hokey religions and ancient
    weapons are no match for a
    good blaster at your side, kid.”
    —Han Solo

    View Slide

  14. Immediate cognition without the use
    of conscious rational processes.
    in·tu·i·tion
    /ˌint(y)o͞oˈiSHən/

    View Slide

  15. View Slide

  16. View Slide

  17. That’s immediate cognition, and you weren’t
    conscious of any rational process being used.

    View Slide

  18. View Slide

  19. Using your
    Intuition

    View Slide

  20. Slow
    Down

    View Slide

  21. 1. Stop what you’re doing
    2. Close your eyes
    3. Take a deep breath
    4. Let it out slowly

    View Slide

  22. “If you just sit and observe, you will
    see how restless your mind is. If you
    try to calm it, it only makes it worse,
    but over time it does calm, and when
    it does, there’s room to hear more
    subtle things—that’s when your
    intuition starts to blossom and you
    start to see things more clearly and be
    in the present more…”

    View Slide

  23. “…Your mind just slows down, and
    you see a tremendous expanse in the
    moment. You see so much more than
    you could see before. It’s a discipline;
    you have to practice it.”

    View Slide

  24. Stop Saying
    “I Don’t Know”

    View Slide

  25. We shut off our intuition when we
    answer questions with, “I don’t know.”

    View Slide

  26. Ask yourself what may be blocking you
    from finding the solution.

    View Slide

  27. You must discover the answer.

    View Slide

  28. The Problem
    Your Code
    Is in

    View Slide

  29. View Slide

  30. 1. Looking in the wrong place.

    View Slide

  31. 2. Wasting time, energy, and resources.

    View Slide

  32. 3. Hurting your reputation as a problem solver.

    View Slide

  33. First, assume the problem is in your code.

    View Slide

  34. Focus on the
    Problem,
    Not aSolution

    View Slide

  35. if (A && B) {
    // the problem must be C
    solveUsingD();
    }

    View Slide

  36. The symptoms may not indicate the real problem.

    View Slide

  37. View Slide

  38. Always get to the heart of the problem.

    View Slide

  39. Debugging the
    Irreproducible
    Problem

    View Slide

  40. Do the symptoms point to
    a potential problem area?

    View Slide

  41. Sometimes we can’t solve the problem.

    View Slide

  42. Rubber
    Ducking

    View Slide

  43. 1. Beg, borrow, steal, buy, fabricate or otherwise obtain a
    rubber duck (bathtub variety).
    From a message by Andrew Errington to the University of Canterbury Linux Users Group mailing list, 7 Nov 2002
    http://lists.ethernal.org/oldarchives/cantlug-0211/msg00174.html

    View Slide

  44. 2. Place rubber duck on desk and inform it you are just
    going to go over some code with it, if that’s all right.
    From a message by Andrew Errington to the University of Canterbury Linux Users Group mailing list, 7 Nov 2002
    http://lists.ethernal.org/oldarchives/cantlug-0211/msg00174.html

    View Slide

  45. 3. Explain to the duck what your code is supposed to do,
    and then go into detail and explain things line by line.
    From a message by Andrew Errington to the University of Canterbury Linux Users Group mailing list, 7 Nov 2002
    http://lists.ethernal.org/oldarchives/cantlug-0211/msg00174.html

    View Slide

  46. 4. At some point you will tell the duck what you are
    doing next and then realize that that is not in fact what
    you are actually doing. The duck will sit there serenely,
    happy in the knowledge that it has helped you on your
    way.
    From a message by Andrew Errington to the University of Canterbury Linux Users Group mailing list, 7 Nov 2002
    http://lists.ethernal.org/oldarchives/cantlug-0211/msg00174.html

    View Slide

  47. Talk through the problem out loud.

    View Slide

  48. Sleep
    on It

    View Slide

  49. Your unconscious kicks in while you sleep.

    View Slide

  50. Develop With
    Purpose

    View Slide

  51. Be intentional.

    View Slide

  52. Grok what it is you are doing.

    View Slide

  53. Feature for
    future release
    Tag
    1.0
    From this point on, “next
    release” means the release
    after 1.0
    production:
    hotfix 0.2
    Bugfixes from rel.
    branch may be
    Tag
    0.2
    Incorporate bugfix in
    develop
    Only bugfixes!
    Start of release
    branch for
    1.0

    View Slide

  54. View Slide

  55. View Slide

  56. 59089,74437,42530,62011,36174,116
    95,99933,75496,69517,24908,95047,
    89328,11274,47096,72374,49884,137
    file_ids

    View Slide

  57. 59089,74437,42530,62011,36174,116
    95,99933,75496,69517,24908,95047,
    89328,11274,47096,72374,49884,137
    file_ids
    137

    View Slide

  58. CREATE TABLE `zip_bundle` (
    `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
    `user_id` int(11) NOT NULL,
    `cart_id` int(11) NOT NULL,
    `file_ids` varchar(100) NOT NULL DEFAULT '',
    PRIMARY KEY (`id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;

    View Slide

  59. “The difference between science as
    it stands now and the Buddhist
    investigative tradition lies in the
    dominance of the third-person,
    objective method in science and
    the refinement and utilization of
    first-person, introspective methods
    in Buddhist contemplation. In my
    view, the combination of the first-
    person method with the third-
    person method offers the promise
    of a real advance in the scientific
    study of consciousness.”

    View Slide

  60. THANK YOU.
    ANY QUESTIONS?
    benramsey.com
    Debugging Zen
    Copyright © 2015 Ben Ramsey
    This work is licensed under Creative Commons Attribution-
    ShareAlike 4.0 International. For uses not covered under this
    license, please contact the author.
    !
    " @ramsey
    # github.com/ramsey
    $ [email protected]
    If you want to talk more, feel free to
    contact me.
    Ramsey, Ben. “Debugging Zen.” Lone Star PHP. Addison Conference Center,
    Addison, TX. 18 Apr. 2015. Conference presentation.
    This presentation was created using Keynote. The text is set in Adobe
    Minion Pro and Open Sans. The source code is set in Fira Sans Mono.
    The iconography is provided by Font Awesome.
    Unless otherwise noted, all photographs are used by permission
    under a Creative Commons license. Please refer to the Photo Credits
    slide for more information.
    joind.in/13563
    %

    View Slide

  61. 1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    PHOTO CREDITS
    1. “Zen Stones / Piedras Zen” by Xisco Biblioni, CC BY-NC-SA
    2.0
    2. “Zeev Suraski, Keynote” by S&S Media, CC BY-SA 2.0
    3. “Andi Gutmans” by Stefan Koopmanschap, CC BY-NC-SA 2.0
    4. “Bug on a leaf, in all the glory of f/2.8” by Y.J. Chua, CC BY-
    ND 2.0
    5. “Pagoda garden” by L Hoffheins, CC BY-NC-ND 2.0
    6. “My Brain on MRI” by Julie Falk, CC BY-NC 2.0
    7. “Ripple Effect” by sea turtle, CC BY-NC-ND 2.0
    8. “Steve Jobs Keynote” by Ben Stanfield, CC BY-NC-SA 2.0
    9. “Zen” by Wulf Forrester-Barker, CC BY-NC-SA 2.0
    10. “Annapurna Mountain” by Dave See, CC BY-NC 2.0
    11. “Blue Flower in Barcelona” by Benjamin Grimmnitz, CC BY
    2.0
    12. “Latest DB Schema” by Stanford EdTech, CC BY-NC-ND 2.0
    13. “day 37” by James Gray-King, CC BY-NC 2.0
    14. “Cheetah stalking” by flowcomm, CC BY 2.0
    15. “The Dalai Lama @ Vancouver Peace Summit” by kris krüg,
    CC BY-NC-ND 2.0
    16. “Rubber ducks exposed /2” by Francesco Minciotti, CC BY-
    NC-ND 2.0
    17. “Notes” by Brady Withers, CC BY 2.0
    18. “Sleeping” by MeditationMusic.net, CC BY-NC-SA 2.0

    View Slide

  62. 19
    20
    21
    PHOTO CREDITS
    19. STAR WARS © 1977 Lucasfilm, Ltd. Used in accordance
    with Fair Use.
    20. DUNE © 1984 Dino de Laurentiis Corporation. Used in
    accordance with Fair Use.
    21. DUNE © 1984 Dino de Laurentiis Corporation. Used in
    accordance with Fair Use.
    22. “Untitled” by DiamondBack Truck Covers, CC BY-SA 2.0
    22

    View Slide