DEV Community

Discussion on: In Defense of Defensive Programming

Collapse
 
merkrynis profile image
Julien Bouvet

Very very nice article.

I think it's a matter of being pragmatic. Defensive programming save some times on debugging, on security fixing, etc...

It's only a matter of implementation details to provide simple and clear way to do so.
Your allow is a very good example, and a lot of ways exist to do the same.
I used to implement validator classes in C#, and it was easy to use, crystal clear, and in the end, with a very limited impact on performances (especially in web tech where those checks, if properly implemented represents a marginal cost compared to page generation, images loading etc...)

Thanks a lot for sharing this with us all :) I will look in your other articles, you just got a new follower :p

Collapse
 
bytebodger profile image
Adam Nathaniel Davis

Thank you for the feedback! And, indeed, I agree with pragmatism. I'm not going to "code shame" anyone because they haven't validated every single input on every single function/method/etc. But I do look askance at anyone who presumes that any such validation represents the "dreaded" defensive programming.