Last Updated: September 09, 2019
·
377
· PatriceKryszto

Defensive programming is the best !

I always liked defensive programming, it is very easy to do and it can solve major crashes that you're probably never expecting to happen...
It is very basic to set up, but it is very powerful in terms of anticipating crashes.

Here are a few examples :

if ( pointer != NULL )
{
do stuff;
}

void function(parameter*)
{
if ( parameter==null) return ;

now we can process the function because our pointer is probably valid.
}

these are 2 simple examples but you'll find them very useful in everyday's life of a code. And they work in every language !