Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2004
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2004

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: RE: Re: Finding errors in my code?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg48243] Re: [mg48218] RE: [mg48060] Re: [mg48057] Finding errors in my code?
  • From: Murray Eisenberg <murray at math.umass.edu>
  • Date: Wed, 19 May 2004 02:42:24 -0400 (EDT)
  • Organization: Mathematics & Statistics, Univ. of Mass./Amherst
  • References: <200405180816.EAA14881@smc.vnet.net>
  • Reply-to: murray at math.umass.edu
  • Sender: owner-wri-mathgroup at wolfram.com

[This is a reply to the original poster.]

Another technique, not exlcusive of inserting Print statements into a
(presumably long and complicated) function definition, is to "debug
before writing the program", that is:

1. Do it step-by-step first, without defining any function, evaluating
each little expression in turn to that it works (with various kinds of
values for the intended input variables).

2. Encapsulate each of the steps, or perhaps groups of the steps, into a
"little" function and test those functions.

Only then combine things into the final program.

An often welcome result of this approach, aside from making debugging 
easy, is you find the final program consists merely of some combination 
of the "little" functions; or that some of those "little" functions are 
themselves of more general use than originally intended.

This approach is hardly unique to Mathematica and works nicely, in fact, 
with any interpreted programming language.  (For a compiled language
it works, too, but with considerably more difficulty, since you
typically have to write program stubs and special-purpose covering
functions, etc., to get it to work.)

David Park wrote:
> We might hope for something better, but I always find that the quickest way
> to debug is to add a Print statement to the code at a judicious point giving
> the values of various state variables. I find this much easier than using
> Trace. The warning and error messages are only a rough guide anyway and
> don't necessarily tell you where the error originates.

-- 
Murray Eisenberg                     murray at math.umass.edu
Mathematics & Statistics Dept.
Lederle Graduate Research Tower      phone 413 549-1020 (H)
University of Massachusetts                413 545-2859 (W)
710 North Pleasant Street            fax   413 545-1801
Amherst, MA 01003-9305




  • Prev by Date: RE: Re: Precision of output
  • Next by Date: evolution matrix and ODEs, i think....
  • Previous by thread: RE: Re: Finding errors in my code?
  • Next by thread: Fw: Finding errors in my code?