Hey everyone, I wanted to get some opinions on a decision I need to make.
I have a library which has a method say:
unsigned short int doSomething(unsigned short int param1)
This method has some code it will execute to do something.
I need some additional functionality, which is to validate that something was done, in doSomething.
I can do this in one of two ways:
The first I can see would be two separate methods:
unsigned short int doSomething(unsigned short int param1)
{
//Do the stuff
}
unsigned short int doSomethingValidate(unsigned short int param1)
{
doSomething(param1);
//write the code to validate that it was done here
}
OR I could do:
unsigned short int doSomething(unsigned short int param1, boolean toValidate=false)
{
//Do the stuff
if(toValidate)
{
//write code to validate it was done
}
}
Outside of micro controllers, I would ALWAYS use the second method, using one method with the optional toValidate boolean parameter.
However, I am wondering if the if logic I would need to write in that method would be too much overhead, considering this method will be called a tremendous amount of the time, and I will always know when calling it whether I need to validate it or not.
I would be curious to know if there are best practices in this case, or just some general opinions.