[Date Index] [Thread Index] [Author Index]
Re: RE: Re: Finding errors in my code?
[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