[Tutor] Should error checking be duplicated for both functions if one function calls another one?
Mark Lawrence
breamoreboy at yahoo.co.uk
Mon Jun 1 22:03:40 CEST 2015
On 01/06/2015 15:37, boB Stepp wrote:
> On Mon, Jun 1, 2015 at 9:33 AM, David Palao <dpalao.python at gmail.com> wrote:
>> Hello,
>> Not sure if I got it, but, in my opinion functions should do only one
>> thing.So if function 2 finds an error, it should raise it. There
>> should be another function (function 1 in your case?) taking care of
>> possible raised errors.
>
> I guess my question was not clearly worded. The idea is that function
> 1 calls another function. Function 1 checks for possible errors that
> are relevant. Some or all of these checks are also relevant to the
> called function. Should the called function also include these
> relevant error checks?
>
> boB
>
No, the end result would be horrendous code bloat if that was applied
across the board. Function 2 should do the checking and raise an error
if there's a problem. Function 1 can catch that and proceed or not as
it sees fit, as can any other piece of code calling function 2. It's
the DRY principle, see http://c2.com/cgi/wiki?DontRepeatYourself
--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.
Mark Lawrence
More information about the Tutor
mailing list