debugging para el no iniciado

71
De Frustrado a Competente Debugging para el no iniciado: Barcamp 2015, Santiago, R.D.

Upload: leonardo-jimenez

Post on 06-Apr-2017

319 views

Category:

Software


0 download

TRANSCRIPT

Page 1: Debugging para el no iniciado

De Frustrado a CompetenteDebugging para el no iniciado:

Barcamp 2015, Santiago, R.D.

Page 2: Debugging para el no iniciado

What we will cover

Barcamp 2015, Santiago, R.D.

- What is debugging- Why is hard- Know yourself- The true path to debugging- The rules of debugging- What debugging displays- Remember

Page 3: Debugging para el no iniciado

About me

Barcamp 2015, Santiago, R.D.

Leonardo Jimenez (Un entusiasta del software)Blog: www.leonardo.docorreo: [email protected]

Co-Founder and Developer @CodetigerWe love Python, We use a ton of stuff

One of the organizers of @pythondo && @Jsdo

Page 4: Debugging para el no iniciado

Barcamp 2015, Santiago, R.D.

Page 5: Debugging para el no iniciado

Can you tell me what debugging means to you?

What is debugging?

Barcamp 2015, Santiago, R.D.

Page 6: Debugging para el no iniciado

What is debugging?

Barcamp 2015, Santiago, R.D.

Can you tell me what debugging means to you?Some frequent answers:

- Make the error go away- Eliminate the errors on the screen- “Resolver…!”

Page 7: Debugging para el no iniciado

What is debugging?

Barcamp 2015, Santiago, R.D.

Most of the answers are related to fixing the actual problem ...

Page 8: Debugging para el no iniciado

What is debugging?

Barcamp 2015, Santiago, R.D.

My (really recent definition) Definition

“Debugging is the process of finding and resolving bugs or defects in the code in a manner that the code is better than the way it was found”

Page 9: Debugging para el no iniciado

What is debugging?

Barcamp 2015, Santiago, R.D.

Debugging Normally includes:

1. Get the bug in the database (if you are lucky)2. Reproduce the problem3. Automate and simplify the test case (if you know what you are doing)4. Find possible infection origins5. Focus on the most likely origins6. Isolate the infection chain7. Correct the defect

Page 10: Debugging para el no iniciado

What is debugging?

Barcamp 2015, Santiago, R.D.

Debugging Normally includes:

1. Get the bug in the database (if you are lucky)2. Reproduce the problem3. Automate and simplify the test case (if you know what you are doing)4. Find possible infection origins5. Focus on the most likely origins6. Isolate the infection chain7. Correct the defect

{Understand the Problem

Page 11: Debugging para el no iniciado

What is debugging?

Barcamp 2015, Santiago, R.D.

Debugging Normally includes:

1. Get the bug in the database (if you are lucky)2. Reproduce the problem3. Automate and simplify the test case (if you know what you are doing)4. Find possible infection origins5. Focus on the most likely origins6. Isolate the infection chain7. Correct the defect{

Search the Problem

Page 12: Debugging para el no iniciado

What is debugging?

Barcamp 2015, Santiago, R.D.

Debugging Normally includes:

1. Get the bug in the database (if you are lucky)2. Reproduce the problem3. Automate and simplify the test case (if you know what you are doing)4. Find possible infection origins5. Focus on the most likely origins6. Isolate the infection chain7. Correct the defect{

Fixing it

Page 13: Debugging para el no iniciado

What is debugging?

Barcamp 2015, Santiago, R.D.

Debugging Normally includes:

1. Get the bug in the database (if you are lucky)2. Reproduce the problem3. Automate and simplify the test case (if you know what you are doing)4. Find possible infection origins5. Focus on the most likely origins6. Isolate the infection chain7. Correct the defect{

Most of your time goes here

Page 14: Debugging para el no iniciado

Why is debugging hard?

Barcamp 2015, Santiago, R.D.

Key Takeaway #1Debugging is a problem of scarcity

Page 15: Debugging para el no iniciado

Why is debugging hard?

Barcamp 2015, Santiago, R.D.

Let’s do an exercise:- Search on Google “Learn to Program”

Page 16: Debugging para el no iniciado

Why is debugging hard?

Barcamp 2015, Santiago, R.D.

Let’s do an exercise:- Search on Google “Learn to Program”

- 1,540,000,000 Results (1.5 Billion results)

Page 17: Debugging para el no iniciado

Why is debugging hard?

Barcamp 2015, Santiago, R.D.

Let’s do another exercise:- Search on Google “Implement an

ordered List”

- 3,020,000 Results

Page 18: Debugging para el no iniciado

Why is debugging hard?

Barcamp 2015, Santiago, R.D.

Let’s do another exercise:- Search on Google “Ordered Hash Table”

- 758,000 Results

Page 19: Debugging para el no iniciado

Why is debugging hard?

Barcamp 2015, Santiago, R.D.

The more advanced your question is,the less easy answers you will find

Page 20: Debugging para el no iniciado

Why is debugging hard?

Barcamp 2015, Santiago, R.D.

Do you remember your first time?

Page 21: Debugging para el no iniciado

Why is debugging hard?

Barcamp 2015, Santiago, R.D.

Do you remember your first time?

print “Hello world”

Page 22: Debugging para el no iniciado

Why is debugging hard?

Barcamp 2015, Santiago, R.D.

Do you remember your first CRUD App?Your first blog?, your first to do list?

What do they have in common?

Page 23: Debugging para el no iniciado

Why is debugging hard?

Barcamp 2015, Santiago, R.D.

Do you remember your first CRUD App?Your first blog?, your first to do list?

What do they have in common?

You knew the whole App!!!

Page 24: Debugging para el no iniciado

Why is debugging hard?

Barcamp 2015, Santiago, R.D.

This is what it feels like working on a new, different and legacy codebase ...

Page 25: Debugging para el no iniciado

Why is debugging hard?

Barcamp 2015, Santiago, R.D.

Page 26: Debugging para el no iniciado

Why is debugging hard?

Barcamp 2015, Santiago, R.D.

The difference between a good developer and a bad developer is understanding.

Page 27: Debugging para el no iniciado

Why is debugging hard?

Barcamp 2015, Santiago, R.D.

The difference between a good developer and a bad developer is understanding.

Understanding of what does not change.

Page 28: Debugging para el no iniciado

Know yourself

Barcamp 2015, Santiago, R.D.

Do you understand the basics of your (Language/Library/framework) or you just did a tutorial?

Page 29: Debugging para el no iniciado

Know yourself

Barcamp 2015, Santiago, R.D.

Do you read the documentation while learning the technology or after something’s break?

Page 30: Debugging para el no iniciado

Know yourself

Barcamp 2015, Santiago, R.D.

Do you know the standard library well or you just copy/paste from stack overflow?

Page 31: Debugging para el no iniciado

Know yourself

Barcamp 2016, Santiago, R.D.

Page 32: Debugging para el no iniciado

Know yourself (example)

Barcamp 2015, Santiago, R.D.

def is_equal(a, b):return a is b

>> is_equal(2, 2)True>> is_equal(4, 3)False

Page 33: Debugging para el no iniciado

Know yourself (example)

Barcamp 2015, Santiago, R.D.

def is_equal(a, b):return a is b

>> value = 256>> is_equal(256, value)?

Page 34: Debugging para el no iniciado

Know yourself (example)

Barcamp 2015, Santiago, R.D.

def is_equal(a, b):return a is b

>> value = 256>> is_equal(256, value)True

Page 35: Debugging para el no iniciado

Know yourself (example)

Barcamp 2015, Santiago, R.D.

def is_equal(a, b):return a is b

>> value = 257>> is_equal(257, value)?

Page 36: Debugging para el no iniciado

Know yourself (example)

Barcamp 2015, Santiago, R.D.

def is_equal(a, b):return a is b

>> value = 257>> is_equal(257, value)False

Page 37: Debugging para el no iniciado

Know yourself (example)

Barcamp 2015, Santiago, R.D.

def is_equal(a, b):return a is b

Why???

Page 38: Debugging para el no iniciado

Know yourself (example)

Barcamp 2015, Santiago, R.D.

def is_equal(a, b):return a is b

Equality is different to Identity

Page 39: Debugging para el no iniciado

In General

Barcamp 2015, Santiago, R.D.

Key Takeaway #2The code can give you the right result for the wrong reasons.

Page 40: Debugging para el no iniciado

Know yourself (example)

Barcamp 2015, Santiago, R.D.

Ruby Example

Page 41: Debugging para el no iniciado

Know yourself (example)

Barcamp 2015, Santiago, R.D.

class Bicycle attr_reader :size, :parts

def initialize(args={}) @size = args[:size] @parts = args[:parts] end

def spares parts.spares endend

Page 42: Debugging para el no iniciado

Know yourself (example)

Barcamp 2015, Santiago, R.D.

class Parts < Array def size parts.size endend

Page 43: Debugging para el no iniciado

Know yourself (example)

Barcamp 2015, Santiago, R.D.

class Part attr_reader :name, :description, :needs_space

def initialize(args) @name = args[:name] @description = args[:description] @needs_spare = args.fetch(:needs_spare, true) endend

Page 44: Debugging para el no iniciado

Know yourself (example)

Barcamp 2015, Santiago, R.D.

# Individual Partschain = Part.new(name: 'chain', description: '10-speed')road_tire = Part.new(name: 'tire_size', description: '23')tape = Part.new(name: 'tape_color', description: 'red')mountain_tire = Part.new(name: 'tire_size', description: '2.1')rear_shock = Part.new(name: 'rear_shock', description: 'Fox')front_shock = Part.new( name: 'front_shock', description: 'Manitou', needs_spare: false)

Page 45: Debugging para el no iniciado

Know yourself (example)

Barcamp 2015, Santiago, R.D.

# Parts Objectsroad_bike_parts = Parts.new([chain, road_tire, tape])mountain_bike_parts = Parts.new([chain, mountain_tire, front_shock, rear_shock])

Page 46: Debugging para el no iniciado

Know yourself (example)

Barcamp 2015, Santiago, R.D.

# Bicycle Objectsroad_bike = Bicycle.new(size: ‘L’, parts: road_bike_parts)mountain_bike = Bicycle.new(size: ‘L’, parts: mountain_bike_parts)

Page 47: Debugging para el no iniciado

Know yourself (example)

Barcamp 2015, Santiago, R.D.

# Property Testsmountain_bike .size # - > ‘L’

mountain_bike.spares# - > [#<Part:0x00000101036770# @name="chain",# @description="10-speed",# @needs_spare=true>,# #<Part:0x0000010101b678# @name="tire_size",# etc ...

Page 48: Debugging para el no iniciado

Know yourself (example)

Barcamp 2015, Santiago, R.D.

# Property Testscombo_parts =

(mountain_bike.parts + road_bike.parts)

combo_parts.size # - > 7

combo_parts.spares # - > NoMethodError: undefined method 'spares'# for #<Array:...>

Page 49: Debugging para el no iniciado

Know yourself (example)

Barcamp 2015, Santiago, R.D.

# Property Testscombo_parts =

(mountain_bike.parts + road_bike.parts)

combo_parts.size # - > 7

combo_parts.spares # - > NoMethodError: undefined method 'spares'# for #<Array:...>

Why?

Page 50: Debugging para el no iniciado

In General

Barcamp 2015, Santiago, R.D.

The code can give you the right result for the wrong reasons.

Page 51: Debugging para el no iniciado

The True Path to Debugging

Barcamp 2015, Santiago, R.D.

Page 52: Debugging para el no iniciado

The True Path to Debugging

Barcamp 2016, Santiago, R.D.

Page 53: Debugging para el no iniciado

In General

Barcamp 2015, Santiago, R.D.

Key Takeaway #3Growing as a software developer means moving from memorisation to understanding

Page 54: Debugging para el no iniciado

In General

Barcamp 2015, Santiago, R.D.

Key Takeaway #4Avoid shotgun surgery become a neurosurgeon.

Page 55: Debugging para el no iniciado

The True Path to Debugging

Barcamp 2015, Santiago, R.D.

- Know Yourself tools - Search within your code- Be one with the universe person who asks

Page 56: Debugging para el no iniciado

The True Path to Debugging

Barcamp 2015, Santiago, R.D.

(You can Name it)

ARE

TOOLS

Page 57: Debugging para el no iniciado

The True Path to Debugging

Barcamp 2015, Santiago, R.D.

LEARN:- When to use it and when not- Learn Many and avoid a lot more- One really well- Learn the principles

Page 58: Debugging para el no iniciado

In General

Barcamp 2015, Santiago, R.D.

Key Takeaway #5Debugging is not a tool, is a mindset.

The mindset name is curiosity.

Be Curious.

Page 59: Debugging para el no iniciado

The True Path to Debugging

Barcamp 2015, Santiago, R.D.

READ THE $#%@$%# MANUAL:- Read the documentation- Read the specifications- Read the code (yes, for Fun)

Page 60: Debugging para el no iniciado

The True Path to Debugging

Barcamp 2015, Santiago, R.D.

If Nothing else works ask, but:

- Make sure you read the documentation- Make your homework- Tried to solve it yourself

Page 61: Debugging para el no iniciado

The True Path to Debugging

Barcamp 2015, Santiago, R.D.

When asking:

- Be respectful- Tell the facts not your theories- Don’t be proud

Page 62: Debugging para el no iniciado

Debugging Rules

Barcamp 2015, Santiago, R.D.

- Understand the system- Make it Fail- Quit Thinking and look- Divide and conquer- Change one thing at a time- Keep up an audit trail- Check if it is on- Talk with another person- If you don't fix it, it ain't fixed

Page 63: Debugging para el no iniciado

Remember?

Barcamp 2015, Santiago, R.D.

Do you remember the definition of Debugging?

Page 64: Debugging para el no iniciado

What is debugging?

Barcamp 2015, Santiago, R.D.

My (really recent definition) Definition

“Debugging is the process of finding and resolving bugs or defects in the code in a manner that the code is better than the way it was found”

Page 65: Debugging para el no iniciado

Remember?

Barcamp 2015, Santiago, R.D.

Does every interaction with your code making it better?

Page 66: Debugging para el no iniciado

Remember?

Barcamp 2015, Santiago, R.D.

Or do you sing ?

99 little bugs in the code99 little bugs in the code

Take one down, patch it around117 little bugs in the code

Page 67: Debugging para el no iniciado

In General

Barcamp 2015, Santiago, R.D.

Key Takeaway #6In order to be an amazing debugger you should be an incredible refactorer.

Page 68: Debugging para el no iniciado

In the end- Don’t rush- Don’t Panic- Understand the problem - Understand your Language- Understand your tools- RTFM

In General

Barcamp 2015, Santiago, R.D.

Page 69: Debugging para el no iniciado

Preguntas??Debugging para el no iniciado:

Barcamp 2015, Santiago, R.D.

Page 70: Debugging para el no iniciado

Barcamp 2015, Santiago, R.D.

Gracias !!

Blog: www.leonardo.docorreo: [email protected]: @leonardoajim

Page 71: Debugging para el no iniciado

De Frustrado a CompetenteDebugging para el no iniciado:

Barcamp 2015, Santiago, R.D.