Defensive
Programming
The Best Defense is a good Offense
Tuesday, February 26, 13
Slide 2
Slide 2 text
little about me
Product, technology and development
consultant
RoR, Python/Django, Performance is my
passion
Development methodologies, agile and
effective patterns
@liorsion, about.me/liorsion
Tuesday, February 26, 13
Slide 3
Slide 3 text
defensive dev
It’s mostly about psychology
Ruby code as example
For every rule there’s an exception
Tuesday, February 26, 13
Slide 4
Slide 4 text
defensive dev
It’s mostly about psychology
Ruby code as example
For every rule there’s an exception
Tuesday, February 26, 13
Slide 5
Slide 5 text
defensive dev
It’s mostly about psychology
Ruby code as example
For every rule there’s an exception
Tuesday, February 26, 13
Slide 6
Slide 6 text
defensive dev
It’s mostly about psychology
Ruby code as example
For every rule there’s an exception
Tuesday, February 26, 13
Slide 7
Slide 7 text
Best practices
Always validate your input - everywhere!
Tuesday, February 26, 13
Slide 8
Slide 8 text
Validate input
Tuesday, February 26, 13
Slide 9
Slide 9 text
dangerous exceptions
Always safeguard from exceptions
Tuesday, February 26, 13
Slide 10
Slide 10 text
naming
Naming is not that important
Tuesday, February 26, 13
Slide 11
Slide 11 text
Multi threading
When in doubt - lock it!
Tuesday, February 26, 13
Slide 12
Slide 12 text
Multi threading
When in doubt - lock it!
Tuesday, February 26, 13
Slide 13
Slide 13 text
More refactoring
Don’t refactor if you don’t know the code
Tuesday, February 26, 13
Slide 14
Slide 14 text
More refactoring
W
r
o
n
g
!
Don’t refactor if you don’t know the code
Tuesday, February 26, 13
Slide 15
Slide 15 text
More refactoring
W
r
o
n
g
!
Tuesday, February 26, 13
Slide 16
Slide 16 text
Best practices
Always validate your input - everywhere!
Tuesday, February 26, 13
Slide 17
Slide 17 text
Validate input
Tuesday, February 26, 13
Slide 18
Slide 18 text
dangerous exceptions
Always safeguard from exceptions
Tuesday, February 26, 13
Slide 19
Slide 19 text
naming
Naming is not that important
Tuesday, February 26, 13
Slide 20
Slide 20 text
naming
Naming is not that important
Tuesday, February 26, 13
Slide 21
Slide 21 text
Multi threading
When in doubt - lock it!
Tuesday, February 26, 13
Slide 22
Slide 22 text
Multi threading
When in doubt - lock it!
Tuesday, February 26, 13
Slide 23
Slide 23 text
Multi threading
When in doubt - lock it!
Tuesday, February 26, 13
Slide 24
Slide 24 text
More refactoring
Don’t refactor if you don’t know the code
Tuesday, February 26, 13
Slide 25
Slide 25 text
More refactoring
Tuesday, February 26, 13
Slide 26
Slide 26 text
why do that?
Don’t know better
Can’t be bothered
Tuesday, February 26, 13
Slide 27
Slide 27 text
why do that?
Don’t know better
Can’t be bothered
Afraid of production meltdown
Tuesday, February 26, 13
Slide 28
Slide 28 text
why do that?
Don’t know better
Can’t be bothered
Afraid of production meltdown
Need to teach
Tuesday, February 26, 13
Slide 29
Slide 29 text
why do that?
Don’t know better
Can’t be bothered
Afraid of production meltdown
Need to fire
Need to teach
Tuesday, February 26, 13
Slide 30
Slide 30 text
why do that?
Don’t know better
Can’t be bothered
Afraid of production meltdown
Need to fire
Why?
Need to teach
Tuesday, February 26, 13
Slide 31
Slide 31 text
Most popular reasons
We’re in a hurry
The code is too complicated
I don’t know what is going on there
There’s code smell in this area
There are no tests
Tuesday, February 26, 13
Slide 32
Slide 32 text
But really..
Fear is a bitch, and is near sighted
Tuesday, February 26, 13
Slide 33
Slide 33 text
space time theories
There’s never enough time
But spending the time saves time, always
Tuesday, February 26, 13
Slide 34
Slide 34 text
space time theories
There’s never enough time
But spending the time saves time, always
On Quality
Tuesday, February 26, 13
Slide 35
Slide 35 text
Fear
Fear is an emotion induced by a perceived threat which
causes entities to quickly pull away from it and usually
hide
People develop specific fears
as a result of learning.
Fear is paralyzing
Paralyze is spiral, technical
debt is collecting => startup
death
Tuesday, February 26, 13
Slide 36
Slide 36 text
Knowing your code
Tuesday, February 26, 13
Slide 37
Slide 37 text
refactor huge code
http://thejoysofcode.com/post/35328929865/when-it-is-announced-i-must-
refactor-5000-lines-of-code
When I see huge methods..
Tuesday, February 26, 13
Slide 38
Slide 38 text
Refactor
Small
Fast
Ongoing
Tuesday, February 26, 13
Slide 39
Slide 39 text
defense
Be aware, always
Tuesday, February 26, 13
Slide 40
Slide 40 text
Patterns, really?
Tuesday, February 26, 13
Slide 41
Slide 41 text
psychology
Don’t punish mistakes
Don’t punish a task that spirals FOR GOOD
REASONS
In short - don’t punish
Tuesday, February 26, 13
Slide 42
Slide 42 text
Why should we care?
Tuesday, February 26, 13
Slide 43
Slide 43 text
My work here is done
Find me: @liorsion
Find funny images: http://thejoysofcode.com
Tuesday, February 26, 13