Say it like this
- We need to use defensive programming here
- That code lacks defensive programming practices
- Defensive programming would have caught this issue
Use it at work
Code review
- A bit of defensive programming here: check for null first.
- Let's validate the input. It comes from a third party.
Pushing back
- This is too much defensive programming. The type already guarantees it.
- We don't need to check this twice.
Explaining
- Defensive programming saved us when the API changed.
- I added defensive checks around the payment response.
Don't say this
Defensive programming is a noun and practice, not a verb. Use prepositions like 'apply' or 'use' before it.
Practice
Try it
4 quick exercises
1. You are explaining code quality to a new developer. Which sounds most professional?
2. Before deploying to production, we should _______ defensive programming principles to the API endpoints.
3. Which sentence uses defensive programming incorrectly?
4. Rewrite this sentence using defensive programming: 'We check if things could go wrong before we run the code.'
Say it out loud
Phrase 1 of 3
"We need to use defensive programming here"
We don't save your recording. The word check uses your browser's speech recognition.
More about defensive programming
Real examples(3)
- in a code review
"I think we should add more defensive programming to this function. What happens if the API returns null?"
- in a standup
"We spent yesterday refactoring the login module with better defensive programming practices, and it already caught three edge cases."
- in a team meeting
"The reason we had fewer bugs in the last release was because we emphasized defensive programming during development."
More mistakes(2)
Handle with care. Do not confuse with 'defensive driving' (vehicle safety). Also, it is not about being defensive emotionally in code reviews.
- ✕Defensive programming is optional if you have good tests.✓Defensive programming is still important even with comprehensive tests.
Defensive programming complements testing but is not optional. Both are necessary for robust code.
- ✕We added defensive programming to make the code slower.✓We added defensive programming to make the code more reliable, even if it adds minimal overhead.
The purpose of defensive programming is reliability and safety, not performance degradation.
Other forms(2)
- defensive programming noun
"Defensive programming is a best practice in enterprise software development."
- defensive programming techniques/practices/approach noun (attribute)
"We implemented defensive programming techniques throughout the codebase."
Often used with(4)
- apply defensive programming · Use 'apply' to describe implementing these practices in code
- defensive programming practices · Common phrase referring to specific defensive coding techniques
- defensive programming approach · Describes the overall strategy or methodology
- lack defensive programming · Used when code does not have adequate error handling
Similar words(3)
- robust programming · Similar but broader; emphasizes overall strength rather than error anticipation
- error handling · A specific technique within defensive programming, not a complete synonym
- safe coding practices · Similar focus on preventing bugs, but less specific than defensive programming
Opposites(3)
- offensive programming
- reckless coding
- assuming best case
Questions(5)
- What does defensive programming mean in software engineering?
- Defensive programming is a development approach where programmers anticipate potential problems and handle them preemptively. It involves adding validation, error handling, and checks for edge cases to prevent bugs and unexpected behavior in production. Instead of assuming inputs are always valid or that external systems will always respond correctly, defensive programmers write code that gracefully handles failures and invalid data.
- How do you use defensive programming in a sentence at work?
- You can use it as a noun phrase: 'We should apply defensive programming to this module,' or 'This code lacks defensive programming practices.' You can also use it attributively: 'We need a defensive programming approach here,' or in discussions: 'Defensive programming would have prevented this bug.'
- Is defensive programming formal or informal?
- Defensive programming is neutral in formality. It is professional and appropriate for both casual team discussions and formal documentation. You will hear it in standup meetings, code reviews, and technical specifications equally. It is not slang, but it is also not overly formal or academic.
- What are examples of defensive programming techniques?
- Examples include input validation (checking user data before processing), null checks (verifying objects exist before using them), try-catch blocks (handling exceptions), assertions (testing assumptions), default values (providing fallbacks), logging (recording unexpected behavior), and boundary checks (ensuring values are within expected ranges).
- Why is defensive programming important?
- Defensive programming reduces the number of bugs that reach production, improves system reliability, makes code easier to maintain, and prevents crashes from unexpected inputs or system failures. It also demonstrates professional code quality and reduces the time spent on emergency bug fixes after deployment.



