SlideShare a Scribd company logo
THE ART OF
DEFENSIVE
PROGRAMMING
MEETUP CIREBON DEV #3
IPAN ARDIAN
<HELLO!/>
Ipan Ardian
Sr. Software Engineer
Indosystem & Loket (GoJek Group)
9+ years’ experience
http://ipanardian.com
2
WHAT’S DEFENSIVE
PROGRAMMING
Let’s start with the definition first
3
4
Defensive programming is a form of
defensive design intended to ensure
the continuing function of a piece of
software under unforeseen
circumstances. Defensive
programming practices are often
used where high availability, safety or
security is needed — Wikipedia
WHY DEFENSIVE
PROGRAMMING
Does it matter
5
6
WW3, ALMOST…
In 1980, NORAD reported that the US was under missile attack.
The problem was caused by a faulty circuit, a possibility the
reporting software hadn’t taken into account.
DEADLY RADIATION THERAPY
A bug in the code controlling the Therac-25 radiation therapy
machine was directly responsible for at least five patient
deaths in the 1980s when it administered excessive quantities
of X-rays.
BUGS
7
ROCKET LAUNCH ERRORS
The European Space Agency’s Ariane 5 Flight 501 was
destroyed 40 seconds after takeoff (June 4, 1996). The US$1
billion prototype rocket self-destructed due to a bug in the
on-board guidance software.
LOST IN SPACE
One of the subcontractors NASA used when building its Mars
climate orbiter had used English units instead of the intended
metric system, which caused the orbiter’s thrusters to work
incorrectly. Due to this bug, the orbiter crashed almost
immediately when it arrived at Mars in 1999. The cost of the
project was $327 million.
“You can’t sleep well if you are
not confident that your last
commit didn’t take down the
whole application”
8
9
Know The Language
10
11
Try to be as strict as possible. Assert that
your input values are what you expect.
Never Trust
User Input
Don’t write STUPID code,
use SOLID code!!
Write SOLID Code
12
13
From STUPID to SOLID Code!
STUPID
Singleton
Tight Coupling
Untestability
Premature Optimization
Indescriptive Naming
Duplication
SOLID
Single Responsibility Principle
Open/Closed Principle
Liskov Substitution Principle
Interface Segregation Principle
Dependency Inversion Principle
Writing unit tests will help you adhering to common
principles such as High Cohesion, Single Responsibility, Low
Coupling and right object composition
Test
test test!
14
15
ACCEPTANCE TEST
FUNCTIONAL TEST
UNIT TEST
As developers shouldn’t trust others developers’ code.
We shouldn’t trust our code neither.
Code Review
16
Stop hoping your users will report
errors. Monitor and fix crashes in
real time. Iterate continuously.
Boost efficiency. Improve user
experience.
Tracking Error
17
<THANKS!/>
Any questions?
18
QUIZ TIME
Open https://kahoot.it/

More Related Content

PDF
Liran Tal - StrangerDanger - Finding Security Vulnerabilities Before They Fin...
PDF
Liran tal Stranger Danger Security vulnerabilities - Negev Web Developers mee...
DOCX
Charan Resume
PDF
Mobile application security tools
PDF
Automatically Locating Malicious Packages in Piggybacked Android Apps
PDF
software testing
PPTX
Why do we test software?
Liran Tal - StrangerDanger - Finding Security Vulnerabilities Before They Fin...
Liran tal Stranger Danger Security vulnerabilities - Negev Web Developers mee...
Charan Resume
Mobile application security tools
Automatically Locating Malicious Packages in Piggybacked Android Apps
software testing
Why do we test software?

Similar to The Art of Defensive Programming By Ipan Ardian (20)

PPT
Software testing lecture 10
PDF
DIG1108 Lesson 7
PDF
Unit Testing
PDF
The job of software tester - How do I see software testing
PPT
Why test software
PDF
100% Code Coverage in Real World Software
PPTX
Understanding Key Concepts and Applications in Week 11: A Comprehensive Overv...
PPTX
It’s a world of bugs after all
PPTX
Greenfield Effect: Patterns for Effective Disaster Delivery
PDF
10 Big Ideas from Industry
PDF
Selective 97 things every programmer should know
PDF
97 thingseveryprogrammershouldknow
PDF
Technical debt in space jesse warden - 100yss 2015
PPTX
An introduction to Software Testing and Test Management
PDF
Market Aligned Skills Training (MAST) – Software Testing Training Module
PDF
Security as Code (Second Early Release) Bk Sarthak Das
PDF
Security as Code (Second Early Release) Bk Sarthak Das
PDF
Driven to Tests
PDF
Lecture 01 - 02 Introduction to Quality Assurance.pdf
PPTX
Code - Fu: Defensive Programming
Software testing lecture 10
DIG1108 Lesson 7
Unit Testing
The job of software tester - How do I see software testing
Why test software
100% Code Coverage in Real World Software
Understanding Key Concepts and Applications in Week 11: A Comprehensive Overv...
It’s a world of bugs after all
Greenfield Effect: Patterns for Effective Disaster Delivery
10 Big Ideas from Industry
Selective 97 things every programmer should know
97 thingseveryprogrammershouldknow
Technical debt in space jesse warden - 100yss 2015
An introduction to Software Testing and Test Management
Market Aligned Skills Training (MAST) – Software Testing Training Module
Security as Code (Second Early Release) Bk Sarthak Das
Security as Code (Second Early Release) Bk Sarthak Das
Driven to Tests
Lecture 01 - 02 Introduction to Quality Assurance.pdf
Code - Fu: Defensive Programming
Ad

Recently uploaded (20)

PDF
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
PPTX
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
PDF
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
PPTX
Construction Project Organization Group 2.pptx
PPTX
web development for engineering and engineering
PPTX
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
PDF
Operating System & Kernel Study Guide-1 - converted.pdf
PPTX
OOP with Java - Java Introduction (Basics)
PDF
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
PPT
Project quality management in manufacturing
PPTX
Welding lecture in detail for understanding
PDF
PPT on Performance Review to get promotions
PPTX
Internet of Things (IOT) - A guide to understanding
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
PDF
Well-logging-methods_new................
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PPTX
Geodesy 1.pptx...............................................
PPTX
Lecture Notes Electrical Wiring System Components
PDF
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
Construction Project Organization Group 2.pptx
web development for engineering and engineering
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
Operating System & Kernel Study Guide-1 - converted.pdf
OOP with Java - Java Introduction (Basics)
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
Project quality management in manufacturing
Welding lecture in detail for understanding
PPT on Performance Review to get promotions
Internet of Things (IOT) - A guide to understanding
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
Well-logging-methods_new................
CYBER-CRIMES AND SECURITY A guide to understanding
Geodesy 1.pptx...............................................
Lecture Notes Electrical Wiring System Components
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
Ad

The Art of Defensive Programming By Ipan Ardian

  • 1. THE ART OF DEFENSIVE PROGRAMMING MEETUP CIREBON DEV #3 IPAN ARDIAN
  • 2. <HELLO!/> Ipan Ardian Sr. Software Engineer Indosystem & Loket (GoJek Group) 9+ years’ experience http://ipanardian.com 2
  • 3. WHAT’S DEFENSIVE PROGRAMMING Let’s start with the definition first 3
  • 4. 4 Defensive programming is a form of defensive design intended to ensure the continuing function of a piece of software under unforeseen circumstances. Defensive programming practices are often used where high availability, safety or security is needed — Wikipedia
  • 6. 6 WW3, ALMOST… In 1980, NORAD reported that the US was under missile attack. The problem was caused by a faulty circuit, a possibility the reporting software hadn’t taken into account. DEADLY RADIATION THERAPY A bug in the code controlling the Therac-25 radiation therapy machine was directly responsible for at least five patient deaths in the 1980s when it administered excessive quantities of X-rays. BUGS
  • 7. 7 ROCKET LAUNCH ERRORS The European Space Agency’s Ariane 5 Flight 501 was destroyed 40 seconds after takeoff (June 4, 1996). The US$1 billion prototype rocket self-destructed due to a bug in the on-board guidance software. LOST IN SPACE One of the subcontractors NASA used when building its Mars climate orbiter had used English units instead of the intended metric system, which caused the orbiter’s thrusters to work incorrectly. Due to this bug, the orbiter crashed almost immediately when it arrived at Mars in 1999. The cost of the project was $327 million.
  • 8. “You can’t sleep well if you are not confident that your last commit didn’t take down the whole application” 8
  • 10. 10
  • 11. 11 Try to be as strict as possible. Assert that your input values are what you expect. Never Trust User Input
  • 12. Don’t write STUPID code, use SOLID code!! Write SOLID Code 12
  • 13. 13 From STUPID to SOLID Code! STUPID Singleton Tight Coupling Untestability Premature Optimization Indescriptive Naming Duplication SOLID Single Responsibility Principle Open/Closed Principle Liskov Substitution Principle Interface Segregation Principle Dependency Inversion Principle
  • 14. Writing unit tests will help you adhering to common principles such as High Cohesion, Single Responsibility, Low Coupling and right object composition Test test test! 14
  • 16. As developers shouldn’t trust others developers’ code. We shouldn’t trust our code neither. Code Review 16
  • 17. Stop hoping your users will report errors. Monitor and fix crashes in real time. Iterate continuously. Boost efficiency. Improve user experience. Tracking Error 17