Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Designing function signature - return value or out parameter

Hi my dear fellow experts,

I am designing one function that must process files in the folder. The function must say how much files it has processed and also if there is error. What is best way to design such function? I am choosing between three choices:

bool ProcessFiles(out int fileCount)
{
  // return true or false
}

int ProcessFiles()
{
  // return -1 when failed
}

int ProcessFiles(out bool success)
{
  // return count
}

Of course this example is rather an illustration to real life problems. I just want to elaborate good strategy.

like image 889
Captain Comic Avatar asked Nov 22 '25 09:11

Captain Comic


2 Answers

I'd go for:

int ProcessFiles() // returns count
{
   if(error)
   {
       throw new MyException();
   }
}
like image 187
Hans Olsson Avatar answered Nov 24 '25 22:11

Hans Olsson


i would go for

 bool ProcessFiles(out int fileCount)
{
  // return true or false
}
like image 22
TalentTuner Avatar answered Nov 24 '25 22:11

TalentTuner



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!