SlideShare a Scribd company logo
Code- Fu:
Defensive Programming
With great power comes great responsibility ~ Peter Paker’s Dad’s Brother Ben
1980
A radiation therapy machine
was directly responsible for
at least 5 patient deaths
1996
A US$1 billion exploded
40 seconds after takeoff
2012
Apple Maps gives us
directions to nowhere
2016
ABSA bank double
charges clients
Why learn another design pattern?
Because: BUGS!
Intro to Code-Fu
Defensive programming, simply
put, is programming with the intent
to anticipate likely failure points.
Defensive programming practices
are often used where high
reliability, safety or security is
needed.
Intro to Code-Fu cont...
Defensive programming aims to improve software and source code, in terms
of:
1. General quality (reduce bugs)
2. Comprehensive code
a. Clean
b. Readable
c. Understandable
d. Reliable
e. Maintainable
f. Testable
g. Robustness
3. Predictable behaviour
Mastering the
ways of Code-Fu
Defensive programming is really
programming for the real world
where if anything can go wrong it
will.
Real world programs
1. Are not in isolation, you can expect user input or external input
1. Are built & maintained by teams and the individuals making the team
can change over time (imagine open source projects)
1. Need to work
External/User input
● Never trust external/user input
● Remember there are also users with malicious intent
What helps
● Protect your code from invalid data (data validation)
● User whitelists not blacklists
● Use database abstraction (e.g. PDO for PHP)
We work in Teams
● Trust your fellow developers but DON’T trust their code
● Defensive Programming is much like Defensive Driving assume that
everyone around us can potentially and possibly make mistakes.
● Teams can consists of individuals working from different planets
What helps
● Enforcing coding standards (naming conversions included)
● Write SOLID code (Encapsulation)
● Write code for the maintainer (The maintainer can be future you)
● Parameter checks at the beginning of a function/method
● Unit tests, Regression testing, Integration tests
Bad programming
// ES5
Check params + Encapsulation
// ES5
Programs need to work
● Imagine paying R200 per month for Software that works 30% of the time
What helps
● Add diagnostic code, logging and tracing (Bugsnag/Sentry)
● Security tests
As a Defensive programmer
you need to have a healthy
dosage of paranoia
Too much Paranoia
Good/Bad?
QUESTIONS?

More Related Content

PPTX
Code - Fu: Defensive Programming
PDF
The pragmatic programmer
PDF
Exception handling in Ruby
PDF
Some Myths in Software Development
PPTX
Cs2 Ch1
PPTX
Competitive Programming
PPTX
Software construction and development.pptx
PPTX
1606125427-week8.pptx
Code - Fu: Defensive Programming
The pragmatic programmer
Exception handling in Ruby
Some Myths in Software Development
Cs2 Ch1
Competitive Programming
Software construction and development.pptx
1606125427-week8.pptx

Similar to Code - Fu: Defensive Programming (20)

PPTX
Defensive programming
PDF
Defensive Coding Crash Course
PPTX
Eirtight writing secure code
PDF
Defensive Coding Crash Course Tutorial
PDF
Defensive Coding Crash Course - ZendCon 2017
PPTX
secure coding techniques unit-iii material
DOCX
Defensive coding practices is one of the most critical proactive s
PPTX
Developing Better Software
PPTX
An Introduction To Software Development - Implementation
PDF
OWASP Secure Coding Quick Reference Guide
PDF
Why Data Security Should Be a Priority in Your Software Development Strategy?
PPTX
Best Practices for Embedding Security in the Development Stage
PDF
Linux Commands, C, C++, Java and Python Exercises For Beginners
PDF
Fixing security by fixing software development
PPTX
LOW LEVEL DESIGN INSPECTION SECURE CODING
PDF
Designing software with security in mind?
PDF
App sec and quality london - may 2016 - v0.5
PPTX
DefensiveProgramming (1).pptx
PPTX
Software Security : From school to reality and back!
DOC
Defensive programming
Defensive Coding Crash Course
Eirtight writing secure code
Defensive Coding Crash Course Tutorial
Defensive Coding Crash Course - ZendCon 2017
secure coding techniques unit-iii material
Defensive coding practices is one of the most critical proactive s
Developing Better Software
An Introduction To Software Development - Implementation
OWASP Secure Coding Quick Reference Guide
Why Data Security Should Be a Priority in Your Software Development Strategy?
Best Practices for Embedding Security in the Development Stage
Linux Commands, C, C++, Java and Python Exercises For Beginners
Fixing security by fixing software development
LOW LEVEL DESIGN INSPECTION SECURE CODING
Designing software with security in mind?
App sec and quality london - may 2016 - v0.5
DefensiveProgramming (1).pptx
Software Security : From school to reality and back!
Ad

Recently uploaded (20)

PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PPTX
Transform Your Business with a Software ERP System
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PDF
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
PDF
medical staffing services at VALiNTRY
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PDF
Nekopoi APK 2025 free lastest update
PDF
System and Network Administration Chapter 2
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PDF
Understanding Forklifts - TECH EHS Solution
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
Transform Your Business with a Software ERP System
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
Upgrade and Innovation Strategies for SAP ERP Customers
VVF-Customer-Presentation2025-Ver1.9.pptx
2025 Textile ERP Trends: SAP, Odoo & Oracle
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
medical staffing services at VALiNTRY
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
How to Migrate SBCGlobal Email to Yahoo Easily
Nekopoi APK 2025 free lastest update
System and Network Administration Chapter 2
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
Understanding Forklifts - TECH EHS Solution
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
Which alternative to Crystal Reports is best for small or large businesses.pdf
Wondershare Filmora 15 Crack With Activation Key [2025
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
Ad

Code - Fu: Defensive Programming

  • 1. Code- Fu: Defensive Programming With great power comes great responsibility ~ Peter Paker’s Dad’s Brother Ben
  • 2. 1980 A radiation therapy machine was directly responsible for at least 5 patient deaths 1996 A US$1 billion exploded 40 seconds after takeoff 2012 Apple Maps gives us directions to nowhere 2016 ABSA bank double charges clients Why learn another design pattern? Because: BUGS!
  • 3. Intro to Code-Fu Defensive programming, simply put, is programming with the intent to anticipate likely failure points. Defensive programming practices are often used where high reliability, safety or security is needed.
  • 4. Intro to Code-Fu cont... Defensive programming aims to improve software and source code, in terms of: 1. General quality (reduce bugs) 2. Comprehensive code a. Clean b. Readable c. Understandable d. Reliable e. Maintainable f. Testable g. Robustness 3. Predictable behaviour
  • 5. Mastering the ways of Code-Fu Defensive programming is really programming for the real world where if anything can go wrong it will.
  • 6. Real world programs 1. Are not in isolation, you can expect user input or external input 1. Are built & maintained by teams and the individuals making the team can change over time (imagine open source projects) 1. Need to work
  • 7. External/User input ● Never trust external/user input ● Remember there are also users with malicious intent What helps ● Protect your code from invalid data (data validation) ● User whitelists not blacklists ● Use database abstraction (e.g. PDO for PHP)
  • 8. We work in Teams ● Trust your fellow developers but DON’T trust their code ● Defensive Programming is much like Defensive Driving assume that everyone around us can potentially and possibly make mistakes. ● Teams can consists of individuals working from different planets What helps ● Enforcing coding standards (naming conversions included) ● Write SOLID code (Encapsulation) ● Write code for the maintainer (The maintainer can be future you) ● Parameter checks at the beginning of a function/method ● Unit tests, Regression testing, Integration tests
  • 10. Check params + Encapsulation // ES5
  • 11. Programs need to work ● Imagine paying R200 per month for Software that works 30% of the time What helps ● Add diagnostic code, logging and tracing (Bugsnag/Sentry) ● Security tests
  • 12. As a Defensive programmer you need to have a healthy dosage of paranoia