Just curious about the good practice of writing codes in C++, take the following codes as an example:
int do_something()
{
bool bHas;
....
....
if (bHas)
{
...
return 1;
}
... do something else
...
return 2;
}
In the above codes, we can see if bool bHas
is set true, then the function will be finished in the middle; otherwise it will continue to execute the rest codes. It is also possible to write the above codes in the following way:
int do_something()
{
bool bHas;
....
....
if (bHas)
{
...
return 1;
}
else
{
... do something else
...
return 2;
}
}
As you can see, this time 'else
' is used to exactly tell what will be done depending on the value of bool bHas
. My question here is: which practice is better? thanks.