DEV Community

What is Defensive Programming🛡️

Wisdom Ikezi on February 01, 2025

Building Code That’s Ready for Anything What is Defensive Programming? Why is Defensive Programming Important? Common Defensive Program...
Collapse
 
fuzzfree profile image
fuzzfree

Nice article.

As a baseline, we must use strict types in PHP, typescript in js etc. (or strongly typed languages of course haha) to avoid basic pitfalls. There are more to defensive programming, the main cases I have seen during all these years come from "logical" errors. Good code review, strong team and unit testing should catch these errors.

Collapse
 
i_am_ziike profile image
Wisdom Ikezi

Absolutely agree!

Collapse
 
lexlohr profile image
Alex Lohr

If you like zod, try valibot.

Collapse
 
i_am_ziike profile image
Wisdom Ikezi

Sure, will give it a try...
Might even make a post about it later on

Collapse
 
pengeszikra profile image
Peter Vivo

This is a real important topic. Url line also important to count as user input on any moment (even first)

Collapse
 
kaellandrade profile image
Micael Andrade

Nice!

Collapse
 
i_am_ziike profile image
Wisdom Ikezi

Thanks

Collapse
 
florian_dollani profile image
Florian Dollani

This is a useful article, but I think you forgot something, validate forms also in the server, maybe you did not forgot it only you wanted to share the concept of Defensive programming.

Collapse
 
i_am_ziike profile image
Wisdom Ikezi • Edited

Appreciate the feedback @florian_dollani

Collapse
 
kobbycoder profile image
kobbycoder

Very insightful

Collapse
 
i_am_ziike profile image
Wisdom Ikezi

Thanks

Collapse
 
razielrodrigues profile image
Raziel Rodrigues

Nice

Collapse
 
i_am_ziike profile image
Wisdom Ikezi

Thanks