J
John Dann
A question that I'm in two minds about - maybe someone more
experienced could offer some advice?
Let's say I have a method in a class whose function is to generate an
image (But it could equally apply to any more complex object that the
method might generate.)
Then it seems to me that I have two options:
1. Set the image as the return value for the function.
2. Have the function update a class property with the new image and
return eg an integer value to denote success or otherwise of the call
to the function.
I'm kind of leaning towards the second option. Although it seems less
elegant and less concise, using an integer as the return value does
give me the option to test the call for different types of errors that
might have occurred in generating the image and then take appropriate
action.
Anyone care to comment on what might be reckoned to be the better
programming practice?
JGD
experienced could offer some advice?
Let's say I have a method in a class whose function is to generate an
image (But it could equally apply to any more complex object that the
method might generate.)
Then it seems to me that I have two options:
1. Set the image as the return value for the function.
2. Have the function update a class property with the new image and
return eg an integer value to denote success or otherwise of the call
to the function.
I'm kind of leaning towards the second option. Although it seems less
elegant and less concise, using an integer as the return value does
give me the option to test the call for different types of errors that
might have occurred in generating the image and then take appropriate
action.
Anyone care to comment on what might be reckoned to be the better
programming practice?
JGD