[Tutor] To error statement or not to error statement

Prasad, Ramit ramit.prasad at jpmorgan.com
Fri May 31 00:10:21 CEST 2013


Jim Mooney wrote:
> Sent: Wednesday, May 22, 2013 11:28 AM
> To: tutor at python.org
> Subject: [Tutor] To error statement or not to error statement
> 
> >> "I find it amusing when novice programmers believe their main job is
> >> preventing programs from crashing. ... More experienced programmers realize
> >> that correct code is great, code that crashes could use improvement, but
> >> incorrect code that doesn't crash is a horrible nightmare."
> 
> Then am I right to assume that rather than put in error statements I
> barely understand at this point, the best thing would be to work the
> hell out of the program in hope of seeing an error?  Does Python have
> something that would do this automatically since I can't see running a
> program a hundred times by hand?
> 
> Mainly, I'm just learning all this stuff for future reference. I
> really doubt I'll need to use nose to find errors in twenty-line
> programs. Print, assert, and staring at it for a long time should be
> enough for now - and the Wing debugger now and then.
> 
> From the varied replies so far, it sounds to me that debugging is more
> of an art than a science. So far the books I've looked at just mention
> the basics but don't get into the philosophy of when and how.
> 
> Jim
> 

If you mostly just write small programs and use them from 
shell/debugger, then I would just never catch any error.
All raised exceptions will automatically be printed by
the interpreter when they kill your code. That will
automatically show the error and the appropriate stack
trace to fix the error. If you combine that with proper
logging (print can be fine for single threads) you
should have everything you need to solve the problem.

Eventually you get better at logging and anticipating
possible problems. 


~Ramit


This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.  


More information about the Tutor mailing list