Let assume that we have a main() function in which we call a createDirectory() function.
In Python for instance, the code would be:
def main():
# Do some stuff
createDirectory(myPath)
# Do some more stuff
To re-use our created directory, I can see at least two ways:
- either the
createDirectory()function returns 0 in case of success, 1 if it fails to create the directory.
If the operation succeeds, we know that we can usemyPathdirectly later. - or it returns the path to the directory in case of success and
Noneif it fails.
My questions are:
- are there any specific names for those two styles: returning a return code (fail, success, etc.) or returning an actual useful value (the path to our created directory in my example)?
- Are there any clear benefits choosing one or the other style?
I usually return meaningful and useful values rather than return codes but I would be interested in knowing why people use the other style.