Slide 1

Slide 1 text

SQUASHING JavaScript Bugs with Todd H Gardner @toddhgardner

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

AGENDA 1. About JavaScript 2. How to fix Bugs 3. Fix Some Bugs 4. Fix More Bugs 5. Design for Debuggability with Todd H Gardner @toddhgardner

Slide 6

Slide 6 text

TITANIUM SPONSORS Platinum Sponsors Gold Sponsors

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

Are you ready to play?

Slide 9

Slide 9 text

''.length C: 2 What will the following JavaScript code return? 1 D: A: undefined B: 1

Slide 10

Slide 10 text

''.length C: 2 1 D: A: undefined B: 1 String.prototype.length returns the number of bytes rather than the number of characters. Unicode characters, like emoji, require two bytes.

Slide 11

Slide 11 text

0.1 + 0.2 C: 0.3000000000004 What will the following JavaScript code return? 2 D: ‘0.3’ A: 0.3 B: 0.2999999999997

Slide 12

Slide 12 text

2 JavaScript's floating point operations have issues with overflow rounding precision. 0.1 + 0.2 C: 0.3000000000004 D: ‘0.3’ A: 0.3 B: 0.2999999999997

Slide 13

Slide 13 text

new Date(2016, 5, 31) C: 2016 May 31 What will the following JavaScript code return? 3 D: 2017 May 31 A: 2016 July 1 B: 2016 June 31

Slide 14

Slide 14 text

3 Months are zero based in Date. This specifies June 31, which overflows to July 1. new Date(2016, 5, 31) C: 2016 May 31 D: 2017 May 31 A: 2016 July 1 B: 2016 June 31

Slide 15

Slide 15 text

new Array(0, 1, Array(2)); C: [0, 1, [object Array]] What will the following JavaScript code return? 4 D: [0, 1, [undefined, undefined]] A: [0, 1, [2]] B: [0, 1, 2]

Slide 16

Slide 16 text

4 Instantiating an Array with multiple arguments creates an Array from those values. However a single argument only specifies the length. new Array(0, 1, Array(2)); C: [0, 1, [object Array]] D: [0, 1, [undefined, undefined]] A: [0, 1, [2]] B: [0, 1, 2]

Slide 17

Slide 17 text

[10, 5, 1].sort() C: [1, 10, 5] What will the following JavaScript code return? 5 D: [5, 10, 1] A: [1, 5, 10] B: [10, 5, 1]

Slide 18

Slide 18 text

5 Array.prototype.sort's default comparator assumes String operations. All values are coerced and compared as Strings. [10, 5, 1].sort() C: [1, 10, 5] D: [5, 10, 1] A: [1, 5, 10] B: [10, 5, 1]

Slide 19

Slide 19 text

WINNER

Slide 20

Slide 20 text

JavaScript Happens

Slide 21

Slide 21 text

Debugging is like being the detective in a crime movie where you're also the murderer “ Filipe Fortes

Slide 22

Slide 22 text

Identify Isolate Resolve Prevent How To Fix Bugs

Slide 23

Slide 23 text

Identify Isolate Resolve Prevent • Development • Testing • Monitoring • User Reports

Slide 24

Slide 24 text

Identify Isolate Resolve Prevent • Development • Testing • Monitoring • User Reports cheaper, better, faster

Slide 25

Slide 25 text

• Context Identify Isolate Resolve Prevent - Browser - Page - User - Script(s)

Slide 26

Slide 26 text

• Timeline Identify Isolate Resolve Prevent Complex State Machine - API(s) - JS App(s) - DOM - Browser

Slide 27

Slide 27 text

• Root Cause Identify Isolate Resolve Prevent - Symptoms - State

Slide 28

Slide 28 text

• Context • Timeline • Root Cause Identify Isolate Resolve Prevent

Slide 29

Slide 29 text

Identify Isolate Resolve Prevent Application Code Browser API DOM Network Services

Slide 30

Slide 30 text

Identify Isolate Resolve Prevent Application Code Browser API DOM Network Services Your level of Control

Slide 31

Slide 31 text

Identify Isolate Resolve Prevent Risk, Change, Impact, & “The Right Way”

Slide 32

Slide 32 text

Identify Isolate Resolve Prevent • Regression Tests Test to check for the recurrence of a bug

Slide 33

Slide 33 text

Identify Isolate Resolve Prevent • Process Change - Manual - Automated

Slide 34

Slide 34 text

Identify Isolate Resolve Prevent • Do Nothing Tests and Process have cost. Don’t increase them trivially.

Slide 35

Slide 35 text

Identify Isolate Resolve Prevent • Regression Tests • Process • Do Nothing

Slide 36

Slide 36 text

AGENDA 1. About JavaScript 2. How to fix Bugs 3. Fix Some Bugs 4. Fix More Bugs 5. Design for Debuggability with Todd H Gardner @toddhgardner

Slide 37

Slide 37 text

No content

Slide 38

Slide 38 text

XKCD.com

Slide 39

Slide 39 text

getRANTr introducing

Slide 40

Slide 40 text

No content

Slide 41

Slide 41 text

BUGS BECAUSE JAVASCRIPT

Slide 42

Slide 42 text

37,000,000,000 thousands millions billions ones I’ve helped fix JavaScript Bugs {Track:js} JavaScript Error Monitoring

Slide 43

Slide 43 text

github.com / toddhgardner / getRANTR getRANTr

Slide 44

Slide 44 text

Backbone.SOMETHING.extend({ // all our stuff is here });

Slide 45

Slide 45 text

The fewest number of concepts possible Code Review

Slide 46

Slide 46 text

QA Identified Bug: User cannot delete a rant from their timeline. Think twice, rant once. 1

Slide 47

Slide 47 text

KILL IT! 1 AHHHHHHH!!!!

Slide 48

Slide 48 text

Your Turn 1 Exercise 1

Slide 49

Slide 49 text

Logical Bug • Event PreventDefault • Function context 1

Slide 50

Slide 50 text

1 Concepts: • “Keystone” Users • DOM Inspector • Async Callstacks

Slide 51

Slide 51 text

2 User Identified Bug: Rant text remembered after deleted. Is it paranoia if “they” are actually after you?

Slide 52

Slide 52 text

KILL IT! 2 AHHHHHHH!!!!

Slide 53

Slide 53 text

Your Turn 2 Exercise 2

Slide 54

Slide 54 text

Logical Bug • Empty String • Falsy 2

Slide 55

Slide 55 text

2 Concepts: • Application (Storage) Explorer • Breaking Execution

Slide 56

Slide 56 text

3 Monitoring Identified Bug: Server reporting lots of 400 Requests. Bad Request? I’ll request what I want.

Slide 57

Slide 57 text

3

Slide 58

Slide 58 text

3 AJAX Error POST 400 Bad Request /api/rants/ User Click User Input 0 characters

Slide 59

Slide 59 text

KILL IT! 3 AHHHHHHH!!!!

Slide 60

Slide 60 text

Your Turn 3 Exercise 3

Slide 61

Slide 61 text

Data Bug • User-Form Validation 3

Slide 62

Slide 62 text

3 Concepts: • Network Inspector • Response Previews • JavaScript Debugger

Slide 63

Slide 63 text

4 Monitoring Identified Bug: Singular user generating lots of errors Sucks to be them

Slide 64

Slide 64 text

Cannot read ’substr’ of null 4

Slide 65

Slide 65 text

KILL IT! 4 AHHHHHHH!!!!

Slide 66

Slide 66 text

Your Turn 4 Exercise 4

Slide 67

Slide 67 text

Data Bug • Invalid datatypes from server • Safety-checking data 4

Slide 68

Slide 68 text

4 Concepts: • Network Inspector • Response Previews • JavaScript Debugger

Slide 69

Slide 69 text

AGENDA 1. About JavaScript 2. How to fix Bugs 3. Fix Some Bugs 4. Fix More Bugs 5. Design for Debuggability with Todd H Gardner @toddhgardner

Slide 70

Slide 70 text

No content

Slide 71

Slide 71 text

Are you ready to play?

Slide 72

Slide 72 text

Math.max() C: NaN What will the following JavaScript code return? 1 D: 10e25678 A: Infinity B: -Infinity

Slide 73

Slide 73 text

1 Called with no arguments, Math.max() returns the smallest number in JavaScript. Math.max() C: NaN D: 10e25678 A: Infinity B: -Infinity

Slide 74

Slide 74 text

(function foo(a, b) {}).length C: 2 What will the following JavaScript code return? 2 D: 21 A: undefined B: 0

Slide 75

Slide 75 text

2 Function.prototype.length returns the number of arguments specified in the function definition. (function foo(a, b) {}).length C: 2 D: 21 A: undefined B: 0

Slide 76

Slide 76 text

+"42" C: “43” What will the following JavaScript code return? 3 D: NaN A: 42 B: 43

Slide 77

Slide 77 text

3 'The "+" operator is not preceded by a String, so it is considered arithmetic and attempts to coerce the following value into a Number. The gets evaluated as "0 + 42". +"42" C: “43” D: NaN A: 42 B: 43

Slide 78

Slide 78 text

'' - '' C: What will the following JavaScript code return? 4 D: NaN A: '' B: ''

Slide 79

Slide 79 text

4 '' - '' C: D: NaN A: '' B: '' The "-" operator is always arithmetic, so both items are coerced into Numbers. They cannot be interpreted, and result in NaN.

Slide 80

Slide 80 text

!!"" C: true 5 D: false A: “” B: JavaScript's Number type includes the concepts of positive and negative Infinity.

Slide 81

Slide 81 text

!!"" C: true What will the following JavaScript code return? 5 D: false A: “” B:

Slide 82

Slide 82 text

WINNER

Slide 83

Slide 83 text

AGENDA 1. About JavaScript 2. How to fix Bugs 3. Fix Some Bugs 4. Fix More Bugs 5. Design for Debuggability with Todd H Gardner @toddhgardner

Slide 84

Slide 84 text

5 Developer Identified Bug: Unexpectedly high memory usage. You’ve got 16GB! What else are you going to do with it?

Slide 85

Slide 85 text

KILL IT! 5 AHHHHHHH!!!!

Slide 86

Slide 86 text

Your Turn 5 Exercise 5

Slide 87

Slide 87 text

Memory Bug • Unreleased Objects • Orphaned DOM Trees 5

Slide 88

Slide 88 text

5 Concepts: • Profiler • Timeline

Slide 89

Slide 89 text

6 User Identified Bug: Sometimes slow to load the page. Like you have something better to do?

Slide 90

Slide 90 text

KILL IT! 6 AHHHHHHH!!!!

Slide 91

Slide 91 text

Your Turn 6 Exercise 6

Slide 92

Slide 92 text

Performance Bug • Blocking Assets • Uncompressed Assets 6

Slide 93

Slide 93 text

6 Concepts: • Timeline • Network Preview

Slide 94

Slide 94 text

Monitoring Identified Bug: form.submit is not a function on signup Who would signup for this stupid service anyway? 7

Slide 95

Slide 95 text

7

Slide 96

Slide 96 text

KILL IT! 7 AHHHHHHH!!!!

Slide 97

Slide 97 text

Your Turn 7 Exercise 7

Slide 98

Slide 98 text

3rd-Party Bug • Uncontrolled Changes 7

Slide 99

Slide 99 text

7 Concepts: • External Risk • DOM Inconsistency

Slide 100

Slide 100 text

8 Monitoring Identified Bug: “analytics is not defined” Sounds like a PEBKAC to me. Send them an id-10-t cable. “$ is not defined”

Slide 101

Slide 101 text

8

Slide 102

Slide 102 text

KILL IT! 8 AHHHHHHH!!!!

Slide 103

Slide 103 text

Your Turn 8 Exercise 8

Slide 104

Slide 104 text

Network/Proxy Bug • Poor networks • Active blocking 8

Slide 105

Slide 105 text

8 Concepts: • Load Checking • Simulating Networks • Charles/Fiddler Proxy

Slide 106

Slide 106 text

AGENDA 1. About JavaScript 2. How to fix Bugs 3. Fix Some Bugs 4. Fix More Bugs 5. Design for Debuggability with Todd H Gardner @toddhgardner

Slide 107

Slide 107 text

The web is the most hostile software engineering environment imaginable -- Douglas Crockford “

Slide 108

Slide 108 text

Identify Isolate Resolve Prevent Design for Debuggability

Slide 109

Slide 109 text

Identify Isolate Resolve Prevent • Development • Testing • Monitoring • User Reports cheaper, better, faster

Slide 110

Slide 110 text

Identify Isolate Resolve Prevent Monitoring {Track:js} JavaScript Error Monitoring elastic

Slide 111

Slide 111 text

Identify Isolate Resolve Prevent setTimeout(function() { if (!HAS_LOADED_CONDITION) { trackError('slow load'); } }, 10000); Instrument

Slide 112

Slide 112 text

Simplicity Identify Isolate Resolve Prevent

Slide 113

Slide 113 text

Duplication Abstraction Identify Isolate Resolve Prevent

Slide 114

Slide 114 text

Rule of 3 Identify Isolate Resolve Prevent

Slide 115

Slide 115 text

DOM Identify Isolate Resolve Prevent Network Browser API Application Code

Slide 116

Slide 116 text

Identify Isolate Resolve Prevent Gary Bernhardt Destroy All Software

Slide 117

Slide 117 text

Design for Test (hardware) Identify Isolate Resolve Prevent

Slide 118

Slide 118 text

Debug Mode http://myapp.com?debug Identify Isolate Resolve Prevent

Slide 119

Slide 119 text

Identify Isolate Resolve Prevent Tools {Track:js}

Slide 120

Slide 120 text

Identify Isolate Resolve Prevent Lower the Risk of Change

Slide 121

Slide 121 text

Identify Isolate Resolve Prevent • Regression Tests • Update Process • Do Nothing Think

Slide 122

Slide 122 text

Identify Isolate Resolve Prevent Bug Count as a proxy for Design Quality

Slide 123

Slide 123 text

Identify Isolate Resolve Prevent The Doer- thinger The Enterprise- Ready Cylinder The all- powerful cloud Widgetizer Requests Generic Architecture

Slide 124

Slide 124 text

Identify Isolate Resolve Prevent The Doer- thinger The Enterprise- Ready Cylinder The all- powerful cloud Widgetizer Requests Generic Architecture 51 2 7 0 Bug Count

Slide 125

Slide 125 text

Identify Isolate Resolve Prevent Design for Debuggability

Slide 126

Slide 126 text

AGENDA 1. About JavaScript 2. How to fix Bugs 3. Fix Some Bugs 4. Fix More Bugs 5. Design for Debuggability with Todd H Gardner @toddhgardner

Slide 127

Slide 127 text

{Track:js} JavaScript Error Monitoring

Slide 128

Slide 128 text

{Track:js} JavaScript Error Monitoring

Slide 129

Slide 129 text

TrackJS.com more info and a free 30 day trial

Slide 130

Slide 130 text

SQUASHING JavaScript Bugs with Todd H Gardner @toddhgardner