Re: Where to put the error handing test?

2009-11-24 Thread Bruno Desthuilliers
alex23 a écrit : On Nov 24, 1:15 pm, Peng Yu pengyu...@gmail.com wrote: Suppose that I have function f() that calls g(), I can put a test on the argument 'x' in either g() or f(). I'm wondering what is the common practice. If I put the test in f(), then g() becomes more efficient when other

Re: Where to put the error handing test?

2009-11-24 Thread Paul Miller
On Mon, 23 Nov 2009 22:27:24 -0800, alex23 wrote: As a very rough example: def g(x): try: assert isinstance(x, int) except AssertionError: raise TypeError, excepted int, got %s % type(x) # ... function code goes here def f(x):

Re: Where to put the error handing test?

2009-11-24 Thread Dave Angel
Peng Yu wrote: On Mon, Nov 23, 2009 at 9:44 PM, Lie Ryan lie.1...@gmail.com wrote: Peng Yu wrote: Suppose that I have function f() that calls g(), I can put a test on the argument 'x' in either g() or f(). I'm wondering what is the common practice. My thought is that if I put the test

Re: Where to put the error handing test?

2009-11-24 Thread Steven D'Aprano
On Mon, 23 Nov 2009 21:15:48 -0600, Peng Yu wrote: Suppose that I have function f() that calls g(), I can put a test on the argument 'x' in either g() or f(). I'm wondering what is the common practice. My thought is that if I put the test in g(x), the code of g(x) is safer, but the test is

Re: Where to put the error handing test?

2009-11-24 Thread Peng Yu
On Tue, Nov 24, 2009 at 12:27 AM, alex23 wuwe...@gmail.com wrote: On Nov 24, 1:15 pm, Peng Yu pengyu...@gmail.com wrote: Suppose that I have function f() that calls g(), I can put a test on the argument 'x' in either g() or f(). I'm wondering what is the common practice. If I put the test in

Re: Where to put the error handing test?

2009-11-24 Thread Peng Yu
On Tue, Nov 24, 2009 at 4:58 AM, Dave Angel da...@ieee.org wrote: Peng Yu wrote: On Mon, Nov 23, 2009 at 9:44 PM, Lie Ryan lie.1...@gmail.com wrote: Peng Yu wrote: Suppose that I have function f() that calls g(), I can put a test on the argument 'x' in either g() or f(). I'm wondering

Re: Where to put the error handing test?

2009-11-24 Thread Lie Ryan
Peng Yu wrote: On Tue, Nov 24, 2009 at 4:58 AM, Dave Angel da...@ieee.org wrote: I'll put an extra emphasis on this: Your question is so open-ended as to be unanswerable. I'll still confused by the guideline that an error should be

Re: Where to put the error handing test?

2009-11-24 Thread Steven D'Aprano
On Tue, 24 Nov 2009 10:14:19 -0600, Peng Yu wrote: I'll still confused by the guideline that an error should be caught as early as possible. I think you are confused by what that means. It means the error should be caught as early as possible in *time*, not in the function chain. In Python,

Where to put the error handing test?

2009-11-23 Thread Peng Yu
Suppose that I have function f() that calls g(), I can put a test on the argument 'x' in either g() or f(). I'm wondering what is the common practice. My thought is that if I put the test in g(x), the code of g(x) is safer, but the test is not necessary when g() is called by h(). If I put the

Re: Where to put the error handing test?

2009-11-23 Thread Lie Ryan
Peng Yu wrote: Suppose that I have function f() that calls g(), I can put a test on the argument 'x' in either g() or f(). I'm wondering what is the common practice. My thought is that if I put the test in g(x), the code of g(x) is safer, but the test is not necessary when g() is called by h().

Re: Where to put the error handing test?

2009-11-23 Thread Peng Yu
On Mon, Nov 23, 2009 at 9:44 PM, Lie Ryan lie.1...@gmail.com wrote: Peng Yu wrote: Suppose that I have function f() that calls g(), I can put a test on the argument 'x' in either g() or f(). I'm wondering what is the common practice. My thought is that if I put the test in g(x), the code of

Re: Where to put the error handing test?

2009-11-23 Thread alex23
On Nov 24, 1:15 pm, Peng Yu pengyu...@gmail.com wrote: Suppose that I have function f() that calls g(), I can put a test on the argument 'x' in either g() or f(). I'm wondering what is the common practice. If I put the test in f(), then g() becomes more efficient when other code call g() and