lundi 14 mai 2018

How can I execute a function cleanly off of the return status of two other functions' success?

I have one function which relies on the successful return statuses of two other functions. I.e. if either function is a failure, the third function needs to update something within itself to reflect this, but still proceed. Is there a clean way to execute this third function, without being redundant?

In my case, I have the following, where func1 and func2 are returning either success or failure:

bool status;
bool status2;
status = func1();
status2 = func2();
if (status && status2){
 func3(other_args,true)
else func3(other_args, false);

And I feel like this is not done well at all. My func3 conducts a write of a plethora of information and relies on knowing if either operations that were conducted failed. Is there a cleaner way to implement this third function call?

My first thoughts were:

if (func1 && func2){
    func3(some_other_args, true)
else func3(some_other_args, false)

Is this the right mindset, or is there something much cleaner here?

Aucun commentaire:

Enregistrer un commentaire