debugging para el no iniciado
TRANSCRIPT
De Frustrado a CompetenteDebugging para el no iniciado:
Barcamp 2015, Santiago, R.D.
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
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
Barcamp 2015, Santiago, R.D.
Can you tell me what debugging means to you?
What is debugging?
Barcamp 2015, Santiago, R.D.
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…!”
What is debugging?
Barcamp 2015, Santiago, R.D.
Most of the answers are related to fixing the actual problem ...
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”
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
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
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
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
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
Why is debugging hard?
Barcamp 2015, Santiago, R.D.
Key Takeaway #1Debugging is a problem of scarcity
Why is debugging hard?
Barcamp 2015, Santiago, R.D.
Let’s do an exercise:- Search on Google “Learn to Program”
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)
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
Why is debugging hard?
Barcamp 2015, Santiago, R.D.
Let’s do another exercise:- Search on Google “Ordered Hash Table”
- 758,000 Results
Why is debugging hard?
Barcamp 2015, Santiago, R.D.
The more advanced your question is,the less easy answers you will find
Why is debugging hard?
Barcamp 2015, Santiago, R.D.
Do you remember your first time?
Why is debugging hard?
Barcamp 2015, Santiago, R.D.
Do you remember your first time?
print “Hello world”
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?
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!!!
Why is debugging hard?
Barcamp 2015, Santiago, R.D.
This is what it feels like working on a new, different and legacy codebase ...
Why is debugging hard?
Barcamp 2015, Santiago, R.D.
Why is debugging hard?
Barcamp 2015, Santiago, R.D.
The difference between a good developer and a bad developer is understanding.
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.
Know yourself
Barcamp 2015, Santiago, R.D.
Do you understand the basics of your (Language/Library/framework) or you just did a tutorial?
Know yourself
Barcamp 2015, Santiago, R.D.
Do you read the documentation while learning the technology or after something’s break?
Know yourself
Barcamp 2015, Santiago, R.D.
Do you know the standard library well or you just copy/paste from stack overflow?
Know yourself
Barcamp 2016, Santiago, R.D.
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
Know yourself (example)
Barcamp 2015, Santiago, R.D.
def is_equal(a, b):return a is b
>> value = 256>> is_equal(256, value)?
Know yourself (example)
Barcamp 2015, Santiago, R.D.
def is_equal(a, b):return a is b
>> value = 256>> is_equal(256, value)True
Know yourself (example)
Barcamp 2015, Santiago, R.D.
def is_equal(a, b):return a is b
>> value = 257>> is_equal(257, value)?
Know yourself (example)
Barcamp 2015, Santiago, R.D.
def is_equal(a, b):return a is b
>> value = 257>> is_equal(257, value)False
Know yourself (example)
Barcamp 2015, Santiago, R.D.
def is_equal(a, b):return a is b
Why???
Know yourself (example)
Barcamp 2015, Santiago, R.D.
def is_equal(a, b):return a is b
Equality is different to Identity
In General
Barcamp 2015, Santiago, R.D.
Key Takeaway #2The code can give you the right result for the wrong reasons.
Know yourself (example)
Barcamp 2015, Santiago, R.D.
Ruby Example
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
Know yourself (example)
Barcamp 2015, Santiago, R.D.
class Parts < Array def size parts.size endend
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
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)
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])
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)
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 ...
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:...>
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?
In General
Barcamp 2015, Santiago, R.D.
The code can give you the right result for the wrong reasons.
The True Path to Debugging
Barcamp 2015, Santiago, R.D.
The True Path to Debugging
Barcamp 2016, Santiago, R.D.
In General
Barcamp 2015, Santiago, R.D.
Key Takeaway #3Growing as a software developer means moving from memorisation to understanding
In General
Barcamp 2015, Santiago, R.D.
Key Takeaway #4Avoid shotgun surgery become a neurosurgeon.
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
The True Path to Debugging
Barcamp 2015, Santiago, R.D.
(You can Name it)
ARE
TOOLS
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
In General
Barcamp 2015, Santiago, R.D.
Key Takeaway #5Debugging is not a tool, is a mindset.
The mindset name is curiosity.
Be Curious.
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)
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
The True Path to Debugging
Barcamp 2015, Santiago, R.D.
When asking:
- Be respectful- Tell the facts not your theories- Don’t be proud
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
Remember?
Barcamp 2015, Santiago, R.D.
Do you remember the definition of Debugging?
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”
Remember?
Barcamp 2015, Santiago, R.D.
Does every interaction with your code making it better?
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
In General
Barcamp 2015, Santiago, R.D.
Key Takeaway #6In order to be an amazing debugger you should be an incredible refactorer.
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.
Preguntas??Debugging para el no iniciado:
Barcamp 2015, Santiago, R.D.
Barcamp 2015, Santiago, R.D.
Gracias !!
Blog: www.leonardo.docorreo: [email protected]: @leonardoajim
De Frustrado a CompetenteDebugging para el no iniciado:
Barcamp 2015, Santiago, R.D.