Slide 1

Slide 1 text

Debugging for Distressed Developers by Daniëlle Suurlant

Slide 2

Slide 2 text

Who am I Daniëlle Suurlant Developer @ Samson IT Typically not distressed github.com/dsuurlant twitter.com/dsuurlant www.binarystar.nl (1/1/2014)

Slide 3

Slide 3 text

What’s this about ➔ The Basics ➔ The Tools ➔ The In-Depth: XDebug ➔ The Don’ts and Do Instead ➔ The Best Practices

Slide 4

Slide 4 text

The Basics

Slide 5

Slide 5 text

The Basics ➔ Breakpoints ➔ Stepping ◆ Step Into ◆ Step Over ◆ Step Out ➔ Run To Cursor ➔ Stack trace ➔ Variables

Slide 6

Slide 6 text

The Tools

Slide 7

Slide 7 text

Debugging “tools” ➔ var_dump driven development ➔ console.log ➔ die ➔ alert ➔ print_r

Slide 8

Slide 8 text

Debugging tools ➔ XDebug ➔ Chrome Developer’s Tools / Firebug ➔ PostMan ➔ git bisect

Slide 9

Slide 9 text

XDebug ➔ PHP extension ➔ IDE key

Slide 10

Slide 10 text

Browser Developer’s Tools ➔ Explore all options! ◆ HTML source, CSS styles, source files ◆ Network traffic ◆ XHR requests ◆ JavaScript debugging ➔ Keep a Dev Tool window open ➔ Live editing ◆ ... just don’t refresh

Slide 11

Slide 11 text

PostMan ➔ Headers and authentication ➔ GET, POST, PUT, PATCH ➔ Form data, text, JSON, XML ➔ Quick & basic ➔ Use with XDebug: http://project.dev/api/method/1?XDEBUG_SESSION_START=PHPSTORM

Slide 12

Slide 12 text

git bisect ➔ Binary search algorithm dsu:~/workspace/project (master)> git bisect start dsu:~/workspace/project (master|BISECTING)> git bisect bad dsu:~/workspace/project (master|BISECTING)> git bisect good e765fdf56 Bisecting: 1 revisions left to test after this (roughly 1 steps) [85ae1469e7d2400920c478156f3c7faa66f928a4] Story-324 verification fixes dsu:~/workspace/project ((85ae146...)|BISECTING)> git bisect bad Bisecting: 0 revisions left to test after this (roughly 0 steps) [528da5c4529bb57d029714c96ec26022d77463ba] fixed Story-322 dsu:~/workspace/project ((528da5c...)|BISECTING)> git bisect good 4352658da938e1a5a06c6a5dcf255eb5c7fe6db3 is the first bad commit

Slide 13

Slide 13 text

In-Depth: XDebug

Slide 14

Slide 14 text

Installation ➔ Manual Installation ◆ http://xdebug.org/download.php ◆ Correct PHP version and 32/64 bit ◆ TS = thread safe ➔ Not sure? Wizard! ◆ http://xdebug.org/wizard.php ➔ Check installation

Slide 15

Slide 15 text

Debugging with XDebug: a handy chart

Slide 16

Slide 16 text

Configuration: PHP ➔ Find your php.ini ... all of them zend_extension= "c:/wamp/bin/php/php5.4.12/zend_ext/php_xdebug-2.2.3-5.4-vc9-x86_64.dll" [xdebug] xdebug.remote_enable = 1 xdebug.remote_host = localhost xdebug.remote_port = 9000 xdebug.idekey = "PHPSTORM" xdebug.profiler_enable = off xdebug.profiler_enable_trigger = off xdebug.profiler_output_name = cachegrind.out.%t.%p xdebug.profiler_output_dir = "c:/wamp/tmp"

Slide 17

Slide 17 text

Configuration: IDE ➔ PHPStorm ◆ Settings -> PHP -> Debug ◆ Debug port 9000, accept external connections ➔ Others ◆ IDE key ◆ Debug port ◆ Check FAQ / tutorial

Slide 18

Slide 18 text

Configuration: CLI ➔ Command line (probably) uses different php.ini ◆ Make sure the settings match ➔ Using bash? export XDEBUG_CONFIG="idekey=PHPSTORM"

Slide 19

Slide 19 text

Not working? ➔ IDE key ➔ IDE key ➔ IDE KEY ➔ Port ➔ Restarted server? ➔ Flowchart

Slide 20

Slide 20 text

The Don’ts and Do Instead

Slide 21

Slide 21 text

Breakpoints ➔ Don’t: ◆ Put them on every line in the file ◆ Forget them ➔ Do Instead: ◆ Break on one line, then use stepping ◆ Run to Cursor ◆ Closer to the problem source -> new breakpoint ◆ Clear old breakpoints

Slide 22

Slide 22 text

Stepping ➔ Don’t: ◆ Step into infinity ◆ Step to understand the code ➔ Do Instead: ◆ Stop stepping ◆ Understand the code ◆ Use run to cursor

Slide 23

Slide 23 text

Variables ➔ Don’t: ◆ Examine recursively nested variables to 100+ levels ➔ Do Instead: ◆ Stop clicking ◆ Take a deep breath ◆ Go for a walk

Slide 24

Slide 24 text

Shotgun debugging “Shotgun debugging is a process of making relatively undirected changes to software in the hope that a bug will be perturbed out of existence.” (Source: Wikipedia) ➔ Don’t: ◆ ... ◆ Just don’t ➔ Do Instead: ◆ Use breakpoints

Slide 25

Slide 25 text

The Best Practices

Slide 26

Slide 26 text

Always keep in mind ➔ Don’t panic ➔ Focus on what information you need ➔ Think before you run ➔ Ask a friendly programmer for help ➔ Take necessary breaks

Slide 27

Slide 27 text

➔ Blame doesn’t fix bugs ➔ Boy / Girl scout principle ➔ But... ◆ Does this need to be fixed now? ◆ Does this need to be fixed by me? I didn’t break it

Slide 28

Slide 28 text

Questions?