-1
I have heard that it is good practice to return only true or false (1 or 0) functions, but if I create a function that checks a string, and I want to know what errors occurred in it, I usually return different values, for example:
RETURN 1 - If the string contains a number.
RETURN 2 - If the string contains special characters.
RETURN 3 - If the string contains a letter 'a'.
So my question is, would that be bad programming practice? And if it is, what other way do I return a certain error from a function that checks a string (for example).
NOTE: I return different values to display a more intuitive and user-specific error. I don’t just want to return 1 to say "There is an error", I mean what is the error that happened, so return 1, 2, 3....
It is only bad practice what you do that does not meet the requirements of the project.
– Woss
I totally diverge from this 'good' practice. A function should return what you need from what you can report.
– Reginaldo Rigo