What about return variables?
I specially find it challenging when implementing stored procedures.
Imagine the next stored procedure (wrong syntax, I know, just to show an example):
int procGetIdCompanyByName(string companyName);
It return the Id of the company if it exists in a particular table. Otherwise, it returns -1.
Somehow it's a magic number. Some of the recommendations I've read so far says that I'll really have to do design somthing like that:
int procGetIdCompanyByName(string companyName, bool existsCompany);
By the way, what should it return if the company does not exists? Ok: it will set existesCompany as false, but also will return -1.
Antoher option is to make two separate functions:
bool procCompanyExists(string companyName);
int procGetIdCompanyByName(string companyName);
So a pre-condition for the second stored procedure is that company exists.
But i'm afraid of concurrency, because in this system, a company can be created by another user.
The bottom line by the way is: what do you think about using that kind of "magic numbers" that are relatively known and safe to tell that something is unsuccessful or that something does not exists?