SlideShare a Scribd company logo
Debugging Effectively
@colinodell
@colinodell
Photo by Joseph B // cc by-nc-nd 2.0 // https://flic.kr/p/7GAMBe
Colin O’Dell / @colinodell
• Lead Web Developer & DevOps Engineer
• Director of Technology @ Unleashed Technologies
• Primary language is PHP
• PHP developer for 17 years
• PHP League Leadership Team
• Author/maintainer of PHP CommonMark library
• PHP 7 Upgrade Guide e-book author
• Also experienced in JavaScript, Java, C#, and Python
@colinodell
Overview
I. Importance of debugging
II. Debugging process
III. Tools & Techniques
IV. Q&A
Photo by Roman Boed // cc by 2.0 // https://flic.kr/p/ngwcf1
@colinodell
Debugging is...
Photo by Ewan Cross // cc by-nc-nd 2.0 // https://flic.kr/p/7MCt3m
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
(adjective)
@colinodell
Debugging is...
Photo by Ewan Cross // cc by-nc-nd 2.0 // https://flic.kr/p/7MCt3m
important
@colinodell
Debugging is...
Photo by Ewan Cross // cc by-nc-nd 2.0 // https://flic.kr/p/7MCt3m
the single most
important skill in
programming.
@colinodell
Photo by florianric // cc by 2.0 // https://flic.kr/p/c4QJzC
PlanningCoding
@colinodell
Photo by florianric // cc by 2.0 // https://flic.kr/p/c4QJzC
Planning
Testing &
Debugging
Coding
@colinodell
Debugging is the process of finding and resolving bugs
or defects that prevent correct operation of computer
software or a system.
– Wikipedia
Photo by Stephen Dyrgas // cc by-nc-nd 2.0 // https://flic.kr/p/3eTfWU
Process is the foundation of effective debugging
Process
Photo by Matthew Paulson // cc by-nc-nd 2.0 // https://flic.kr/p/di35xa
Photo by Matthew Paulson // cc by-nc-nd 2.0 // https://flic.kr/p/di35xa
Gain experience with code and tools
Experience
Process
Photo by Matthew Paulson // cc by-nc-nd 2.0 // https://flic.kr/p/di35xa
Develop your intuition
Intuition
Experience
Process
Junior Developers
• Try the “usual” steps
• Clear caches
• Re-install dependencies
• chmod –R 777 *
• Ask somebody else
• Co-worker
• Google
• StackOverflow post
Photo by Yoel Ben-Avraham, with changes // cc by--nd 2.0 // https://flic.kr/p/6pmtQL
@colinodell
XY Problem
Photo by Yoel Ben-Avraham, with changes // cc by--nd 2.0 // https://flic.kr/p/6pmtQL
•I want to solve problem X
•How do I solve X?
@colinodell
XY Problem
Photo by Yoel Ben-Avraham, with changes // cc by--nd 2.0 // https://flic.kr/p/6pmtQL
•I want to solve problem X
•How do I solve X?
•Solution Y might work
•How can I do Y?
@colinodell
Photo by quattrostagioni // cc by 2.0 // https://flic.kr/p/aGjVq8
1.Don’t parse HTML with regex
2.Solve problems the right way @colinodell
“I don’t know why”
“For some reason”
“Doesn’t make sense”
Photo by Stanley Yuu // cc by-nc-nd 2.0 // https://flic.kr/p/pMnfNu
@colinodell
Bugs are logical
Photo by Photofest
@colinodell
“The bug is not moving around in your code,
trying to trick or evade you. It is just siting in
one place, doing the wrong thing in the same
way every time.” – Nick Parlante, Debugging Zen
Photo by GrahamC57 // cc by-nc-nd 2.0 // https://flic.kr/p/cwJi9Q
@colinodell
Assume your
code is the
problem
Photo by Sergio Flores Rosales // cc by-nc-nd 2.0 // https://flic.kr/p/5UHkaW
@colinodell
Systematic Approach
1. Gather information
2. Replicate the issue
3. Identify the culprit
4. Fix it & re-test
5. Mitigate future occurrences
Photo from EduSpiral // cc by-nc-nd 3.0
@colinodell
1. Gather information
• Expected behavior vs.
actual behavior
• Error messages
• Stack traces
Photo from youmustdesireit.wordpress.com
•Screenshots
•Browser & OS
•Date & time
•Log entries
@colinodell
2. Replicate the Issue
Be able to replicate with 100% certainty
Photo by Nick Royer // cc by-sa // https://flic.kr/p/d41ASC
@colinodell
3. Identify the Culprit
Photo by U.S. Navy // cc 2.0 // https://flic.kr/p/n6Wgks
• Be methodical
• Make no assumptions
• Understand the bug @colinodell
4. Fix it & Re-test
• Attempt to replicate again
• Avoid XY problem
• No temporary workarounds!
• Add technical debt
• May introduce other issues
• Never get replaced with true solutions
Photo by Jeff Eaton // cc by-sa 2.0 // https://flic.kr/p/b33rSx
@colinodell
5. Mitigate Future Occurrences
• Add an automated test
• Share your new knowledge
• Project documentation
• Blog post
• StackOverflow
• Submit patch upstream
Photo by marcokalmann // cc by-nc-nd 2.0 // https://flic.kr/p/4CqLMQ
@colinodell
Recap
1. Gather information
2. Replicate the issue
3. Identify the culprit
4. Fix it & re-test
5. Mitigate future occurrences
Photo from EduSpiral // cc by-nc-nd 3.0
@colinodell
Long-Term Results
• Gain experience
• Learn how the system works
• Build heuristics
• Boost confidence
Photo by Glenn Beltz // cc by 2.0 // https://flic.kr/p/i7Csdx
@colinodell
Tools & Techniques
Photo by Alan // cc by-nc-sa 2.0 // https://flic.kr/p/9azLii
@colinodell
Two essential tools
• Integrated development
environment (IDE)
• Interactive debugger
Photo by florianric // cc by 2.0 // https://flic.kr/p/c4QJzC
@colinodell
Integrated Development Environment
•Minimum features:
•Syntax highlighting
•Auto-completion
•Fast code navigation
•Debugger
Photo by florianric // cc by 2.0 // https://flic.kr/p/c4QJzC
@colinodell
Interactive Debugger
•Pause code execution
•Step through execution
•Examine variables
•Explore call stack
Photo by florianric // cc by 2.0 // https://flic.kr/p/c4QJzC
@colinodell
Techniques
1. Trace backwards from known issue
2. Trace forwards from start
3. Binary search
4. Use tools
5. Get help
6. Take a break
Photo by Massmo Relsig // cc by-nc-nd 2.0 // https://flic.kr/p/pFrJCe
@colinodell
1. Trace backwards
•Error is thrown from known location
•Use a debugger
•Establish context
•Work backwards
Photo by Shawn Harquail // cc by-nc 2.0 // https://flic.kr/p/npxFVw
@colinodell
1. Trace backwards
•Error is thrown from known location
•Use a debugger
•Establish context
•Work backwards
a()
b()
c()
d()
Photo by Shawn Harquail // cc by-nc 2.0 // https://flic.kr/p/npxFVw
1. Trace backwards
•Error is thrown from known location
•Use a debugger
•Establish context
•Work backwards
a()
b()
c()
d()
Photo by Shawn Harquail // cc by-nc 2.0 // https://flic.kr/p/npxFVw
1. Trace backwards
•Error is thrown from known location
•Use a debugger
•Establish context
•Work backwards
a()
b()
c()
d()
Photo by Shawn Harquail // cc by-nc 2.0 // https://flic.kr/p/npxFVw
1. Trace backwards
•Error is thrown from known location
•Use a debugger
•Establish context
•Work backwards
a()
b()
c()
d()
Photo by Shawn Harquail // cc by-nc 2.0 // https://flic.kr/p/npxFVw
1. Trace backwards
•Error is thrown from known location
•Use a debugger
•Establish context
•Work backwards
a()
b()
c()
d()
Photo by Shawn Harquail // cc by-nc 2.0 // https://flic.kr/p/npxFVw
2. Trace forwards
•Opposite direction
•Problematic line
isn’t known
•Use debugger or logging
a()
b()
c()
d()
Photo by Shawn Harquail // cc by-nc 2.0 // https://flic.kr/p/npxFVw
2. Trace forwards
•Opposite direction
•Problematic line
isn’t known
•Use debugger or logging
a()
b()
c()
d()
Photo by Shawn Harquail // cc by-nc 2.0 // https://flic.kr/p/npxFVw
2. Trace forwards
•Opposite direction
•Problematic line
isn’t known
•Use debugger or logging
a()
b()
c()
d()
Photo by Shawn Harquail // cc by-nc 2.0 // https://flic.kr/p/npxFVw
2. Trace forwards
•Opposite direction
•Problematic line
isn’t known
•Use debugger or logging
a()
b()
c()
d()
Photo by Shawn Harquail // cc by-nc 2.0 // https://flic.kr/p/npxFVw
3. Divide & Conquer
• Identify different code sections
• Set breakpoints at the boundaries
• Isolate issue to one particular area
• Focus efforts on that area
@colinodell
@colinodell
@colinodell
@colinodell
✓
X
@colinodell
@colinodell
4. Use tools
•Variable dumps
•Debug toolbars
•Console utility
•Profilers
•git bisect
•netcat
•curl
•strace
•etc.
Photo by florianric // cc by 2.0 // https://flic.kr/p/c4QJzC
@colinodell
Variable dumps
Photo by Joseph B // cc by-nc-nd 2.0 // https://flic.kr/p/7GAMBe
•Print to output:
•var_dump()
•pprint()
•puts()
•Log to file
•file_put_contents()
•Logger.debug()
@colinodell
Photo by Joseph B // cc by-nc-nd 2.0 // https://flic.kr/p/7GAMBe
Debug toolbars
@colinodell
Photo by Joseph B // cc by-nc-nd 2.0 // https://flic.kr/p/7GAMBe
Console Utility
Drupal: drush
Drupal Console
Symfony: bin/console
Laravel: artisan
Magento: n98-magerun
@colinodell
Performance Profiling
Identify slowness:
• Bottlenecks
• Resource hogs
• Inefficient code
Photo by Alan Stark // cc by-sa 2.0 // https://flic.kr/p/dn3qjx
Tools:
• Blackfire (freemium)
• New Relic (freemium)
• xhprof (open-source)
@colinodell
git bisect
v1.7 ? ? ? ? ? ? ? HEAD
Photo by unbekannt270 // cc by 2.0 // https://flic.kr/p/oHReqm
@colinodell
git bisect
v1.7 ? ? ? ? ? ? ? HEAD
Photo by unbekannt270 // cc by 2.0 // https://flic.kr/p/oHReqm
@colinodell
git bisect
v1.7 ? ? ? BAD ? ? ? HEAD
Photo by unbekannt270 // cc by 2.0 // https://flic.kr/p/oHReqm
@colinodell
git bisect
v1.7 ? ? ? BAD BAD BAD BAD HEAD
Photo by unbekannt270 // cc by 2.0 // https://flic.kr/p/oHReqm
@colinodell
git bisect
v1.7 ? GOOD ? BAD BAD BAD BAD HEAD
Photo by unbekannt270 // cc by 2.0 // https://flic.kr/p/oHReqm
@colinodell
git bisect
v1.7 GOOD GOOD ? BAD BAD BAD BAD HEAD
Photo by unbekannt270 // cc by 2.0 // https://flic.kr/p/oHReqm
@colinodell
git bisect
v1.7 GOOD GOOD
X BAD BAD BAD BAD HEAD
Photo by unbekannt270 // cc by 2.0 // https://flic.kr/p/oHReqm
abcd123 is the first bad commit
@colinodell
git bisect
Photo by unbekannt270 // cc by 2.0 // https://flic.kr/p/oHReqm
@colinodell
# of Commits # of Tests
9 4
90 8
900 16
Scales logarithmically – runs in O(log N)
Photo by Joseph B // cc by-nc-nd 2.0 // https://flic.kr/p/7GAMBe
netcat
@colinodell
Photo by Joseph B // cc by-nc-nd 2.0 // https://flic.kr/p/7GAMBe
strace
@colinodell
5. Get help
• RTFM / RTFD
• Project forums or issue queue
• StackOverflow, IRC, etc.
• Ask a colleague
• Expert in that area
• Senior developer
• Rubber ducking
Photo by Hiromitsu Morimoto // cc by-sa 2.0 // https://flic.kr/p/6Vzzaa
@colinodell
6. Take a break
Photo by Kristina Alexadnerson // cc by-nc-nd 2.0 // https://flic.kr/p/cFEcDC
• Clear your mind; start fresh
• Forget invalid assumptions
• Recharge your batteries
• Let your subconscious work on it
@colinodell
Four things to walk away with
1. Computers aren’t random,
and neither are bugs
2. Persistence will always pay off
3. Don’t be afraid to dive deep
4. Don’t make assumptions or
take things for granted
Photo by Kristina Alexadnerson // cc by-nc-nd 2.0 // https://flic.kr/p/dvEpfY
@colinodell
Questions?
Photo by Marcello Maria Perongini // cc by-nc-nd 2.0 // https://flic.kr/p/6KDtm
@colinodell
Learn More
• https://web.duke.edu/cps001/notes/Debugging.pdf
• http://www.fiveminutegeekshow.com/20
• http://blog.codeunion.io/2014/09/03/teaching-novices-how-to-debug-
code/
• https://www.jetbrains.com/phpstorm/help/debugging.html
• http://www.sitepoint.com/debugging-git-blame-bisect/
• http://unix.stackexchange.com/a/50099/80744
• http://codeception.com/docs/01-Introduction
• http://chadfowler.com/blog/2014/01/26/the-magic-of-strace/
• http://c2.com/cgi/wiki?RubberDucking
Photo by Samantha Marx // cc by 2.0 // https://flic.kr/p/8KrU1R
@colinodell
Thanks!
@colinodell / colinodell@gmail.com
Photo by Steve Rotman // cc by-nc-nd 2.0 // https://flic.kr/p/xiBK

More Related Content

PPTX
Debugging Effectively - DrupalCon Nashville 2018
PPTX
Debugging Effectively - All Things Open 2017
PPTX
Debugging Effectively - ZendCon 2016
PPTX
Debugging Effectively - DrupalCon Europe 2016
PPTX
Debugging Effectively - PHP UK 2017
PPTX
Debugging Effectively - SunshinePHP 2017
PPTX
Debugging Effectively - php[world] 2015
PPTX
Debugging Effectively - SymfonyLive San Francisco 2015
Debugging Effectively - DrupalCon Nashville 2018
Debugging Effectively - All Things Open 2017
Debugging Effectively - ZendCon 2016
Debugging Effectively - DrupalCon Europe 2016
Debugging Effectively - PHP UK 2017
Debugging Effectively - SunshinePHP 2017
Debugging Effectively - php[world] 2015
Debugging Effectively - SymfonyLive San Francisco 2015

What's hot (20)

PPTX
Debugging Effectively
PPTX
Debugging Effectively - Frederick Web Tech 9/6/16
PDF
Git inter-snapshot public
PDF
DO YOU WANT TO USE A VCS
PDF
Let the contribution begin
PDF
PDF
Feedback en continu grâce au TDD et au AsCode
PPT
Effective Git - EclipseCon 2011 tutorial
PDF
Ankara jug mayıs 2013 sunumu
PDF
21st Century CPAN Testing: CPANci
PDF
Cutting Code Quickly - LLEWELLYN FALCO
PPTX
Cutting code quickly
PPTX
Intro. to Git and Github
PDF
Developing Apps With React Native
PDF
Updated non-lab version of Level Up. Delivered at LOPSA-East, May 3, 2014.
PDF
Git Anti-Patterns - Extended Version With 28 Common Anti-Patterns) - SCTurkey...
PDF
Git For The Android Developer
ODP
PDF
JDD 2016 - Bartosz Majsak - Meet The Assertable Chaos Monkeys
PPS
I can has API? A Love Story
Debugging Effectively
Debugging Effectively - Frederick Web Tech 9/6/16
Git inter-snapshot public
DO YOU WANT TO USE A VCS
Let the contribution begin
Feedback en continu grâce au TDD et au AsCode
Effective Git - EclipseCon 2011 tutorial
Ankara jug mayıs 2013 sunumu
21st Century CPAN Testing: CPANci
Cutting Code Quickly - LLEWELLYN FALCO
Cutting code quickly
Intro. to Git and Github
Developing Apps With React Native
Updated non-lab version of Level Up. Delivered at LOPSA-East, May 3, 2014.
Git Anti-Patterns - Extended Version With 28 Common Anti-Patterns) - SCTurkey...
Git For The Android Developer
JDD 2016 - Bartosz Majsak - Meet The Assertable Chaos Monkeys
I can has API? A Love Story
Ad

Similar to Debugging Effectively - ConFoo Montreal 2019 (20)

PPTX
Notes on Debugging
PDF
Become a Better Developer with Debugging Techniques for Drupal (and more!)
PDF
Debugging in Software Engineering SE Unit-4 Part-6.pdf
PDF
EduSparkz Thunder Thursday Debugging Code
PDF
Effective code reviews
PDF
Effective code reviews
PDF
PHP Static Code Review
PPTX
How to fix bug or defects in software
ODP
The Art Of Debugging
PDF
Ln monitoring repositories
PPT
debugging (1).ppt
PPT
An important characteristic of a test suite that is computed by a dynamic ana...
PPTX
PPTX
It Works On Dev
PDF
Effective codereview | Dave Liddament | CODEiD
PPTX
Debugging Approaches.pptx
PDF
Debugging, Monitoring and Profiling in TYPO3
 
PPT
PHP - Introduction to PHP Bugs - Debugging
PDF
Масштабируемый и эффективный фаззинг Google Chrome
PDF
An Introduction To Software Development - Final Review
Notes on Debugging
Become a Better Developer with Debugging Techniques for Drupal (and more!)
Debugging in Software Engineering SE Unit-4 Part-6.pdf
EduSparkz Thunder Thursday Debugging Code
Effective code reviews
Effective code reviews
PHP Static Code Review
How to fix bug or defects in software
The Art Of Debugging
Ln monitoring repositories
debugging (1).ppt
An important characteristic of a test suite that is computed by a dynamic ana...
It Works On Dev
Effective codereview | Dave Liddament | CODEiD
Debugging Approaches.pptx
Debugging, Monitoring and Profiling in TYPO3
 
PHP - Introduction to PHP Bugs - Debugging
Масштабируемый и эффективный фаззинг Google Chrome
An Introduction To Software Development - Final Review
Ad

More from Colin O'Dell (20)

PPTX
Demystifying Unicode - Longhorn PHP 2021
PPTX
Releasing High Quality Packages - Longhorn PHP 2021
PPTX
Releasing High Quality PHP Packages - ConFoo Montreal 2019
PPTX
Automating Deployments with Deployer - php[world] 2018
PPTX
Releasing High-Quality Packages - php[world] 2018
PPTX
CommonMark: Markdown Done Right - ZendCon 2017
PDF
Rise of the Machines: PHP and IoT - ZendCon 2017
PPTX
Hacking Your Way To Better Security - DrupalCon Baltimore 2017
PPTX
Automating Your Workflow with Gulp.js - php[world] 2016
PPTX
Rise of the Machines: PHP and IoT - php[world] 2016
PPTX
Hacking Your Way to Better Security - ZendCon 2016
PPTX
Hacking Your Way to Better Security - PHP South Africa 2016
PPTX
CommonMark: Markdown done right - Nomad PHP September 2016
PPTX
Hacking Your Way To Better Security - Dutch PHP Conference 2016
PDF
Hacking Your Way To Better Security - php[tek] 2016
PDF
CommonMark: Markdown Done Right
PPTX
PHP 7 Crash Course
PDF
Hacking Your Way To Better Security
PPTX
Introduction to league/commonmark
PPTX
PHP 7 Crash Course - php[world] 2015
Demystifying Unicode - Longhorn PHP 2021
Releasing High Quality Packages - Longhorn PHP 2021
Releasing High Quality PHP Packages - ConFoo Montreal 2019
Automating Deployments with Deployer - php[world] 2018
Releasing High-Quality Packages - php[world] 2018
CommonMark: Markdown Done Right - ZendCon 2017
Rise of the Machines: PHP and IoT - ZendCon 2017
Hacking Your Way To Better Security - DrupalCon Baltimore 2017
Automating Your Workflow with Gulp.js - php[world] 2016
Rise of the Machines: PHP and IoT - php[world] 2016
Hacking Your Way to Better Security - ZendCon 2016
Hacking Your Way to Better Security - PHP South Africa 2016
CommonMark: Markdown done right - Nomad PHP September 2016
Hacking Your Way To Better Security - Dutch PHP Conference 2016
Hacking Your Way To Better Security - php[tek] 2016
CommonMark: Markdown Done Right
PHP 7 Crash Course
Hacking Your Way To Better Security
Introduction to league/commonmark
PHP 7 Crash Course - php[world] 2015

Recently uploaded (20)

PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PDF
medical staffing services at VALiNTRY
PDF
Nekopoi APK 2025 free lastest update
PDF
top salesforce developer skills in 2025.pdf
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PPTX
CHAPTER 2 - PM Management and IT Context
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
Softaken Excel to vCard Converter Software.pdf
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PPTX
L1 - Introduction to python Backend.pptx
PDF
PTS Company Brochure 2025 (1).pdf.......
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PDF
System and Network Administration Chapter 2
PPTX
Operating system designcfffgfgggggggvggggggggg
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
wealthsignaloriginal-com-DS-text-... (1).pdf
medical staffing services at VALiNTRY
Nekopoi APK 2025 free lastest update
top salesforce developer skills in 2025.pdf
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
CHAPTER 2 - PM Management and IT Context
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
Upgrade and Innovation Strategies for SAP ERP Customers
Softaken Excel to vCard Converter Software.pdf
VVF-Customer-Presentation2025-Ver1.9.pptx
L1 - Introduction to python Backend.pptx
PTS Company Brochure 2025 (1).pdf.......
2025 Textile ERP Trends: SAP, Odoo & Oracle
System and Network Administration Chapter 2
Operating system designcfffgfgggggggvggggggggg
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
Navsoft: AI-Powered Business Solutions & Custom Software Development

Debugging Effectively - ConFoo Montreal 2019

  • 2. Photo by Joseph B // cc by-nc-nd 2.0 // https://flic.kr/p/7GAMBe Colin O’Dell / @colinodell • Lead Web Developer & DevOps Engineer • Director of Technology @ Unleashed Technologies • Primary language is PHP • PHP developer for 17 years • PHP League Leadership Team • Author/maintainer of PHP CommonMark library • PHP 7 Upgrade Guide e-book author • Also experienced in JavaScript, Java, C#, and Python @colinodell
  • 3. Overview I. Importance of debugging II. Debugging process III. Tools & Techniques IV. Q&A Photo by Roman Boed // cc by 2.0 // https://flic.kr/p/ngwcf1 @colinodell
  • 4. Debugging is... Photo by Ewan Cross // cc by-nc-nd 2.0 // https://flic.kr/p/7MCt3m _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ (adjective) @colinodell
  • 5. Debugging is... Photo by Ewan Cross // cc by-nc-nd 2.0 // https://flic.kr/p/7MCt3m important @colinodell
  • 6. Debugging is... Photo by Ewan Cross // cc by-nc-nd 2.0 // https://flic.kr/p/7MCt3m the single most important skill in programming. @colinodell
  • 7. Photo by florianric // cc by 2.0 // https://flic.kr/p/c4QJzC PlanningCoding @colinodell
  • 8. Photo by florianric // cc by 2.0 // https://flic.kr/p/c4QJzC Planning Testing & Debugging Coding @colinodell
  • 9. Debugging is the process of finding and resolving bugs or defects that prevent correct operation of computer software or a system. – Wikipedia Photo by Stephen Dyrgas // cc by-nc-nd 2.0 // https://flic.kr/p/3eTfWU
  • 10. Process is the foundation of effective debugging Process Photo by Matthew Paulson // cc by-nc-nd 2.0 // https://flic.kr/p/di35xa
  • 11. Photo by Matthew Paulson // cc by-nc-nd 2.0 // https://flic.kr/p/di35xa Gain experience with code and tools Experience Process
  • 12. Photo by Matthew Paulson // cc by-nc-nd 2.0 // https://flic.kr/p/di35xa Develop your intuition Intuition Experience Process
  • 13. Junior Developers • Try the “usual” steps • Clear caches • Re-install dependencies • chmod –R 777 * • Ask somebody else • Co-worker • Google • StackOverflow post Photo by Yoel Ben-Avraham, with changes // cc by--nd 2.0 // https://flic.kr/p/6pmtQL @colinodell
  • 14. XY Problem Photo by Yoel Ben-Avraham, with changes // cc by--nd 2.0 // https://flic.kr/p/6pmtQL •I want to solve problem X •How do I solve X? @colinodell
  • 15. XY Problem Photo by Yoel Ben-Avraham, with changes // cc by--nd 2.0 // https://flic.kr/p/6pmtQL •I want to solve problem X •How do I solve X? •Solution Y might work •How can I do Y? @colinodell
  • 16. Photo by quattrostagioni // cc by 2.0 // https://flic.kr/p/aGjVq8 1.Don’t parse HTML with regex 2.Solve problems the right way @colinodell
  • 17. “I don’t know why” “For some reason” “Doesn’t make sense” Photo by Stanley Yuu // cc by-nc-nd 2.0 // https://flic.kr/p/pMnfNu @colinodell
  • 18. Bugs are logical Photo by Photofest @colinodell
  • 19. “The bug is not moving around in your code, trying to trick or evade you. It is just siting in one place, doing the wrong thing in the same way every time.” – Nick Parlante, Debugging Zen Photo by GrahamC57 // cc by-nc-nd 2.0 // https://flic.kr/p/cwJi9Q @colinodell
  • 20. Assume your code is the problem Photo by Sergio Flores Rosales // cc by-nc-nd 2.0 // https://flic.kr/p/5UHkaW @colinodell
  • 21. Systematic Approach 1. Gather information 2. Replicate the issue 3. Identify the culprit 4. Fix it & re-test 5. Mitigate future occurrences Photo from EduSpiral // cc by-nc-nd 3.0 @colinodell
  • 22. 1. Gather information • Expected behavior vs. actual behavior • Error messages • Stack traces Photo from youmustdesireit.wordpress.com •Screenshots •Browser & OS •Date & time •Log entries @colinodell
  • 23. 2. Replicate the Issue Be able to replicate with 100% certainty Photo by Nick Royer // cc by-sa // https://flic.kr/p/d41ASC @colinodell
  • 24. 3. Identify the Culprit Photo by U.S. Navy // cc 2.0 // https://flic.kr/p/n6Wgks • Be methodical • Make no assumptions • Understand the bug @colinodell
  • 25. 4. Fix it & Re-test • Attempt to replicate again • Avoid XY problem • No temporary workarounds! • Add technical debt • May introduce other issues • Never get replaced with true solutions Photo by Jeff Eaton // cc by-sa 2.0 // https://flic.kr/p/b33rSx @colinodell
  • 26. 5. Mitigate Future Occurrences • Add an automated test • Share your new knowledge • Project documentation • Blog post • StackOverflow • Submit patch upstream Photo by marcokalmann // cc by-nc-nd 2.0 // https://flic.kr/p/4CqLMQ @colinodell
  • 27. Recap 1. Gather information 2. Replicate the issue 3. Identify the culprit 4. Fix it & re-test 5. Mitigate future occurrences Photo from EduSpiral // cc by-nc-nd 3.0 @colinodell
  • 28. Long-Term Results • Gain experience • Learn how the system works • Build heuristics • Boost confidence Photo by Glenn Beltz // cc by 2.0 // https://flic.kr/p/i7Csdx @colinodell
  • 29. Tools & Techniques Photo by Alan // cc by-nc-sa 2.0 // https://flic.kr/p/9azLii @colinodell
  • 30. Two essential tools • Integrated development environment (IDE) • Interactive debugger Photo by florianric // cc by 2.0 // https://flic.kr/p/c4QJzC @colinodell
  • 31. Integrated Development Environment •Minimum features: •Syntax highlighting •Auto-completion •Fast code navigation •Debugger Photo by florianric // cc by 2.0 // https://flic.kr/p/c4QJzC @colinodell
  • 32. Interactive Debugger •Pause code execution •Step through execution •Examine variables •Explore call stack Photo by florianric // cc by 2.0 // https://flic.kr/p/c4QJzC @colinodell
  • 33. Techniques 1. Trace backwards from known issue 2. Trace forwards from start 3. Binary search 4. Use tools 5. Get help 6. Take a break Photo by Massmo Relsig // cc by-nc-nd 2.0 // https://flic.kr/p/pFrJCe @colinodell
  • 34. 1. Trace backwards •Error is thrown from known location •Use a debugger •Establish context •Work backwards Photo by Shawn Harquail // cc by-nc 2.0 // https://flic.kr/p/npxFVw @colinodell
  • 35. 1. Trace backwards •Error is thrown from known location •Use a debugger •Establish context •Work backwards a() b() c() d() Photo by Shawn Harquail // cc by-nc 2.0 // https://flic.kr/p/npxFVw
  • 36. 1. Trace backwards •Error is thrown from known location •Use a debugger •Establish context •Work backwards a() b() c() d() Photo by Shawn Harquail // cc by-nc 2.0 // https://flic.kr/p/npxFVw
  • 37. 1. Trace backwards •Error is thrown from known location •Use a debugger •Establish context •Work backwards a() b() c() d() Photo by Shawn Harquail // cc by-nc 2.0 // https://flic.kr/p/npxFVw
  • 38. 1. Trace backwards •Error is thrown from known location •Use a debugger •Establish context •Work backwards a() b() c() d() Photo by Shawn Harquail // cc by-nc 2.0 // https://flic.kr/p/npxFVw
  • 39. 1. Trace backwards •Error is thrown from known location •Use a debugger •Establish context •Work backwards a() b() c() d() Photo by Shawn Harquail // cc by-nc 2.0 // https://flic.kr/p/npxFVw
  • 40. 2. Trace forwards •Opposite direction •Problematic line isn’t known •Use debugger or logging a() b() c() d() Photo by Shawn Harquail // cc by-nc 2.0 // https://flic.kr/p/npxFVw
  • 41. 2. Trace forwards •Opposite direction •Problematic line isn’t known •Use debugger or logging a() b() c() d() Photo by Shawn Harquail // cc by-nc 2.0 // https://flic.kr/p/npxFVw
  • 42. 2. Trace forwards •Opposite direction •Problematic line isn’t known •Use debugger or logging a() b() c() d() Photo by Shawn Harquail // cc by-nc 2.0 // https://flic.kr/p/npxFVw
  • 43. 2. Trace forwards •Opposite direction •Problematic line isn’t known •Use debugger or logging a() b() c() d() Photo by Shawn Harquail // cc by-nc 2.0 // https://flic.kr/p/npxFVw
  • 44. 3. Divide & Conquer • Identify different code sections • Set breakpoints at the boundaries • Isolate issue to one particular area • Focus efforts on that area @colinodell
  • 50. 4. Use tools •Variable dumps •Debug toolbars •Console utility •Profilers •git bisect •netcat •curl •strace •etc. Photo by florianric // cc by 2.0 // https://flic.kr/p/c4QJzC @colinodell
  • 51. Variable dumps Photo by Joseph B // cc by-nc-nd 2.0 // https://flic.kr/p/7GAMBe •Print to output: •var_dump() •pprint() •puts() •Log to file •file_put_contents() •Logger.debug() @colinodell
  • 52. Photo by Joseph B // cc by-nc-nd 2.0 // https://flic.kr/p/7GAMBe Debug toolbars @colinodell
  • 53. Photo by Joseph B // cc by-nc-nd 2.0 // https://flic.kr/p/7GAMBe Console Utility Drupal: drush Drupal Console Symfony: bin/console Laravel: artisan Magento: n98-magerun @colinodell
  • 54. Performance Profiling Identify slowness: • Bottlenecks • Resource hogs • Inefficient code Photo by Alan Stark // cc by-sa 2.0 // https://flic.kr/p/dn3qjx Tools: • Blackfire (freemium) • New Relic (freemium) • xhprof (open-source) @colinodell
  • 55. git bisect v1.7 ? ? ? ? ? ? ? HEAD Photo by unbekannt270 // cc by 2.0 // https://flic.kr/p/oHReqm @colinodell
  • 56. git bisect v1.7 ? ? ? ? ? ? ? HEAD Photo by unbekannt270 // cc by 2.0 // https://flic.kr/p/oHReqm @colinodell
  • 57. git bisect v1.7 ? ? ? BAD ? ? ? HEAD Photo by unbekannt270 // cc by 2.0 // https://flic.kr/p/oHReqm @colinodell
  • 58. git bisect v1.7 ? ? ? BAD BAD BAD BAD HEAD Photo by unbekannt270 // cc by 2.0 // https://flic.kr/p/oHReqm @colinodell
  • 59. git bisect v1.7 ? GOOD ? BAD BAD BAD BAD HEAD Photo by unbekannt270 // cc by 2.0 // https://flic.kr/p/oHReqm @colinodell
  • 60. git bisect v1.7 GOOD GOOD ? BAD BAD BAD BAD HEAD Photo by unbekannt270 // cc by 2.0 // https://flic.kr/p/oHReqm @colinodell
  • 61. git bisect v1.7 GOOD GOOD X BAD BAD BAD BAD HEAD Photo by unbekannt270 // cc by 2.0 // https://flic.kr/p/oHReqm abcd123 is the first bad commit @colinodell
  • 62. git bisect Photo by unbekannt270 // cc by 2.0 // https://flic.kr/p/oHReqm @colinodell # of Commits # of Tests 9 4 90 8 900 16 Scales logarithmically – runs in O(log N)
  • 63. Photo by Joseph B // cc by-nc-nd 2.0 // https://flic.kr/p/7GAMBe netcat @colinodell
  • 64. Photo by Joseph B // cc by-nc-nd 2.0 // https://flic.kr/p/7GAMBe strace @colinodell
  • 65. 5. Get help • RTFM / RTFD • Project forums or issue queue • StackOverflow, IRC, etc. • Ask a colleague • Expert in that area • Senior developer • Rubber ducking Photo by Hiromitsu Morimoto // cc by-sa 2.0 // https://flic.kr/p/6Vzzaa @colinodell
  • 66. 6. Take a break Photo by Kristina Alexadnerson // cc by-nc-nd 2.0 // https://flic.kr/p/cFEcDC • Clear your mind; start fresh • Forget invalid assumptions • Recharge your batteries • Let your subconscious work on it @colinodell
  • 67. Four things to walk away with 1. Computers aren’t random, and neither are bugs 2. Persistence will always pay off 3. Don’t be afraid to dive deep 4. Don’t make assumptions or take things for granted Photo by Kristina Alexadnerson // cc by-nc-nd 2.0 // https://flic.kr/p/dvEpfY @colinodell
  • 68. Questions? Photo by Marcello Maria Perongini // cc by-nc-nd 2.0 // https://flic.kr/p/6KDtm @colinodell
  • 69. Learn More • https://web.duke.edu/cps001/notes/Debugging.pdf • http://www.fiveminutegeekshow.com/20 • http://blog.codeunion.io/2014/09/03/teaching-novices-how-to-debug- code/ • https://www.jetbrains.com/phpstorm/help/debugging.html • http://www.sitepoint.com/debugging-git-blame-bisect/ • http://unix.stackexchange.com/a/50099/80744 • http://codeception.com/docs/01-Introduction • http://chadfowler.com/blog/2014/01/26/the-magic-of-strace/ • http://c2.com/cgi/wiki?RubberDucking Photo by Samantha Marx // cc by 2.0 // https://flic.kr/p/8KrU1R @colinodell
  • 70. Thanks! @colinodell / colinodell@gmail.com Photo by Steve Rotman // cc by-nc-nd 2.0 // https://flic.kr/p/xiBK

Editor's Notes

  • #5: What are some words For me: fun challenge
  • #7: Take this one step further Why is that?
  • #8: How much time coding? 2/3rds
  • #9: According to the Mythical Man Month, 1/6th ½ is testing/debugging How much - actually writing code vs getting it working Area where it’s worthwhile to become efficient
  • #10: READ SLOWLY Shouldn’t be done haphazardly
  • #13: Like intuition, but not Understanding without proof Clarity; accuracy; precision -- Focus on the process Experience and “sixth sense” will come with time NEXT: Debugging process
  • #14: BE NICE / CONSTRUCTIVE
  • #15: TODO ADD NOTES
  • #16: When you give up on the proper approach Apply workaround instead Improper solutions will cause issues later NEXT - EXAMPLE
  • #17: Base85-encoded Don’t be clever TRANSITION NEEDED!!
  • #18: Magical thinking
  • #20: Article sneaky
  • #21: Bugs are almost always based on faulty assumptions 95% in your code If helping others, assume their code is problem Challenge their assumptions Take with grain of salt
  • #23: Define the symptoms Collect everything you can
  • #24: Automated tests preferred, but manual is okay too LEGOS
  • #25: Understand the fundamental nature Exactly why
  • #32: Other nice-to-haves: File syncing Git integration Run tools PhpStorm, Sublime Text, vim NOT Notepad++ or Dreamweaver
  • #33: Debuggers are awesome tool … Better than primitive approaches Examine in real time Xdebug Chrome developer tools
  • #34: Click 4 times Dive in Look at call stack
  • #35: Advanced breakpoints Grouping Conditions
  • #37: Stack trace Grep for error message Set breakpoint For example
  • #38: Examine variables How did I get here? – call stack
  • #43: Log/output results at different steps Identify where things start going wrong
  • #44: Log/output results at different steps Identify where things start going wrong
  • #45: Log/output results at different steps Identify where things start going wrong
  • #46: Log/output results at different steps Identify where things start going wrong
  • #53: Debugger is critical Not only tool Tools are not a substitute for thinking
  • #64: Scales logarithmically – runs in O(log N) 9 commits - 4 tests 10x: 90 commits – 8 tests 100x: 900 commits - 16 tests
  • #65: Scales logarithmically – runs in O(log N) 9 commits - 4 tests 10x: 90 commits – 8 tests 100x: 900 commits - 16 tests
  • #68: END TOOLS SECTION
  • #69: Fifth technique
  • #71: 1. There is ALWAYS a logical explanation 3. Great learning opportunity 4. Challenge everything
  • #72: ? Other Questions? Talk afterwards or contact me
  • #74: Thank you guys I’d appreciate feedback