Slide 1

Slide 1 text

php[world] 11/16/2017 Opening The Black Box

Slide 2

Slide 2 text

Howdy! Dustin Younse @milsyobtaf I’m an engineer at Acquia https://github.com/milsyobtaf/prez

Slide 3

Slide 3 text

What Is Debugging?

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

What Is Debugging?

Slide 10

Slide 10 text

Nothing But Text?

Slide 11

Slide 11 text

• CSS aggregated but not cached • JS blocked in the browser • File permissions in sites/default/files Nothing But Text?

Slide 12

Slide 12 text

• Mostly a semantic difference • 5 minutes vs 5 hours? • “Fixed” vs understood and corrected Debugging vs Troubleshooting

Slide 13

Slide 13 text

What Is The Black Box?

Slide 14

Slide 14 text

• Non-technical education • Self taught web skills • Above average Googling abilities • Late nights staring at error messages A Familiar Story?

Slide 15

Slide 15 text

What Is Drupal?

Slide 16

Slide 16 text

Mental Model of Drupal

Slide 17

Slide 17 text

Mental Model of Drupal

Slide 18

Slide 18 text

Mental Model of Drupal

Slide 19

Slide 19 text

Mental Model of Drupal

Slide 20

Slide 20 text

Mental Model of Drupal

Slide 21

Slide 21 text

Mental Model of Drupal

Slide 22

Slide 22 text

Start At The Beginning

Slide 23

Slide 23 text

When All You Have Is A Hammer CC by 2.0 https://www.flickr.com/photos/raindrift/7095238893/

Slide 24

Slide 24 text

Text Editors • “Text Editors” • Text Editors • IDEs

Slide 25

Slide 25 text

• Notepad (Windows) • Text Edit (Mac) • Nano (Linux / Mac) “Text Editors”

Slide 26

Slide 26 text

• Notepad++ (Windows) • Dreamweaver (Mac / Windows) • Sublime Text (Mac / Linux / Windows) • Atom (Mac / Linux / Windows) • Microsoft VS Code (Mac / Linux / Windows) • vim (Mac / Linux) Text Editors

Slide 27

Slide 27 text

• PHPStorm (Mac / Linux / Windows) • Eclipse (Mac / Linux / Windows) • Komodo (Mac / Linux / Windows) Integrated Development Environments

Slide 28

Slide 28 text

• emacs (Mac / Linux / Unix / Everything else) Operating Systems With Built In Text Editors

Slide 29

Slide 29 text

Development Environments • On your server • On your machine • On your machine, but it acts like the server

Slide 30

Slide 30 text

Development Environments • FTP Development • “Cowboy coding” • Local Environments • MAMP / LAMP / Vagrant • Next generation • Kalabox / Lando CLI (And other Docker setups) • DrupalVM / Homestead (And other Vagrant setups)

Slide 31

Slide 31 text

• FTP Development • “Cowboy coding” • No version control up front • Little debugging visibility • Log files (maybe), debug statements • Watchdog logs (maybe) FTP Development

Slide 32

Slide 32 text

• print_r() • Raw dump of a variable or context, no formatting • print_r($node); •

• dsm() / kint()
• Formatted dump of a variable or context
• dsm($node);
Debug Statements in Code

              

Slide 33

Slide 33 text

• MAMP / Dev Desktop / Native LAMP • Code runs entirely locally • Added bonus of offline work, no internet required • print_r(), dsm(), kint(), but also more • xdebug Local Development

Slide 34

Slide 34 text

• Kalabox / Lando with Pantheon / Acquia integration • DrupalVM / Homestead and other Vagrant boxes • print_r(), dsm(), kint(), xdebug • Very accurate performance profiling • XHProf • Blackfire • Tidewater Local Development: The Next Generation

Slide 35

Slide 35 text

What’s xdebug?

Slide 36

Slide 36 text

• Hitting pause on code execution • Inspecting the current state of “the stack” • Modifying values live xdebug: Step Through Debugging

Slide 37

Slide 37 text

Something Is Broken!

Slide 38

Slide 38 text

No content

Slide 39

Slide 39 text

Relax.

Slide 40

Slide 40 text

No content

Slide 41

Slide 41 text

Relax.

Slide 42

Slide 42 text

Remember Cobble’s Knot

Slide 43

Slide 43 text

• Is something not showing up? • New content - is it published? • Old content - are permissions set properly? • Is something showing up that shouldn’t? • Raw HTML and Javascript in a WYSIWYG field? What’s Broken?

Slide 44

Slide 44 text

• Log Files • You should learn how to find your log files 
 before you need your log files • multitail • Linux / Mac utility to easily view logs
 with more options than tail Work From The Bottom Up

Slide 45

Slide 45 text

• Custom Module • template.php / .theme file • Theme Template Where Is It Broken?

Slide 46

Slide 46 text

No content

Slide 47

Slide 47 text

The Scientific Method

Slide 48

Slide 48 text

• Change one thing at a time • Test that change • Repeat Finally, Debugging

Slide 49

Slide 49 text

• Save your progress as you work • Recreate your Features or config yml • Makes rabbit holes manageable git Is Your Friend

Slide 50

Slide 50 text

• Let’s you isolate changes between commits git bisect Is Your Friend

Slide 51

Slide 51 text

git bisect Is Your Friend

Slide 52

Slide 52 text

git bisect Is Your Friend

Slide 53

Slide 53 text

• Remove your debug statements • Ensure you only changed as much as you 
 needed to change • You only commit print_r(‘Butts’); to master once git diff Is Your Friend

Slide 54

Slide 54 text

git blame Finds Your Enemies

Slide 55

Slide 55 text

git blame Finds Your Enemies

Slide 56

Slide 56 text

git blame Is Your Friend

Slide 57

Slide 57 text

• Can help you track down who wrote 
 the offending code • This should not be a witch hunt • This should be a chance to find 
 context for the issue git annotate Is Your Friend

Slide 58

Slide 58 text

Other Debugging Methods

Slide 59

Slide 59 text

• Walk away. Seriously. • Talk to a coworker. • Talk to a rubber duck. • Write it down. By hand. Debugging Techniques

Slide 60

Slide 60 text

Make The Future Easier

Slide 61

Slide 61 text

• watchdog() (D7) • \Drupal::logger() (D8) • Monolog • syslog Module • https://www.elastic.co/blog/heya-elastic-stack-and-x-pack • https://loggly.com • https://www.sumologic.com • Write a test! • Simpletest / PHPUnit / Behat Proactive Debugging

Slide 62

Slide 62 text

• The Art of Troubleshooting by Jason Maxham • https://artoftroubleshooting.com/book/ • Debugging: The 9 Indispensable Rules for Finding Even the Most Elusive Software and Hardware Problems by David Agans • http://debuggingrules.com • Debugging During Development in Drupal 8 by Allie Jones • https://www.gitbook.com/book/zivtech/debug-tools-for-drupal8/ • Using the PhpStorm Debugger by JetBrains • https://confluence.jetbrains.com/x/_idqAw • Maniac Magee by Jerry Spinelli • https://www.worldcat.org/oclc/20422223 Further
 Reading

Slide 63

Slide 63 text

Thanks!
 Questions?
 War stories?
 @milsyobtaf https://github.com/milsyobtaf/prez