Thread Subject: Coding practises - debug?

Subject: Coding practises - debug?

From: Sven

Date: 19 Nov, 2007 09:23:49

Message: 1 of 3

Hi all,

This is a question about how many of the developers here,
well, develop.

I'm currently working on a project that involves repetition
of an algorithm over a series of data sets. I spend most of
the time concentrating on one data set, and improving the
algorithm on that set. This involves a whole bunch of plots
and variables printed to the screen (in-code) to aid in
understanding how my changes worked.

When I'm satisfied with a change, I then reactivate my loop,
and see how things came out over all of my data sets.

At this point I have a problem, as I end up giving myself
epilepsy as all the plots and figure windows flick back and
forth for each iteration of my data set loop.

So, my question is, how would you guys normally get around
this? Obviously, going over code and
commenting/uncommenting any plot lines is a little
tedious... perhaps I could encase all of my plot/debug lines
in an if-statement, and then just toggle a variable at the
top of my program to turn on/off printing.

Is there anything inside matlab that allows me to do this
effectively? Even better would be something that, when not
in debug mode, ignores these sections of code entirely (thus
getting a tiny cpu increase by ignoring the if-statement
comparison).

Any comments or tips would be great.

Cheers,
Sven.

Subject: Coding practises - debug?

From: John D'Errico

Date: 19 Nov, 2007 09:58:15

Message: 2 of 3

"Sven " <sven.holcombe@removethis.gmail.com> wrote in message <fhrkn5
$f57$1@fred.mathworks.com>...
> Hi all,
>
> This is a question about how many of the developers here,
> well, develop.
>
> I'm currently working on a project that involves repetition
> of an algorithm over a series of data sets. I spend most of
> the time concentrating on one data set, and improving the
> algorithm on that set. This involves a whole bunch of plots
> and variables printed to the screen (in-code) to aid in
> understanding how my changes worked.
>
> When I'm satisfied with a change, I then reactivate my loop,
> and see how things came out over all of my data sets.
>
> At this point I have a problem, as I end up giving myself
> epilepsy as all the plots and figure windows flick back and
> forth for each iteration of my data set loop.
>
> So, my question is, how would you guys normally get around
> this? Obviously, going over code and
> commenting/uncommenting any plot lines is a little
> tedious... perhaps I could encase all of my plot/debug lines
> in an if-statement, and then just toggle a variable at the
> top of my program to turn on/off printing.
>
> Is there anything inside matlab that allows me to do this
> effectively? Even better would be something that, when not
> in debug mode, ignores these sections of code entirely (thus
> getting a tiny cpu increase by ignoring the if-statement
> comparison).
>
> Any comments or tips would be great.

Write your code in smaller pieces. As you do,
make sure that each piece works properly.
When you get it right, you do not need to
return to it. Cell mode in the editor is a good
way to do this testing.

Learn to write carefully, thinking about each
code segment as you go. Think out the flow
of your code in advance.

Use/download/develop an "idiom" library that
has many small tools, tailored to your specific
class of problems. Idioms are small snippets
of code to do specific tasks. You reuse these
snippets in different applications, but as long
as they are tested and well commented, you
need never write them more than once. You
will find many such tools on the file exchange.

http://www.mathworks.com/matlabcentral/fileexchange/loadCategory.do

HTH,
John

Subject: Coding practises - debug?

From: Steven Lord

Date: 20 Nov, 2007 18:20:30

Message: 3 of 3


"Sven " <sven.holcombe@removethis.gmail.com> wrote in message
news:fhrkn5$f57$1@fred.mathworks.com...
> Hi all,
>
> This is a question about how many of the developers here,
> well, develop.
>
> I'm currently working on a project that involves repetition
> of an algorithm over a series of data sets. I spend most of
> the time concentrating on one data set, and improving the
> algorithm on that set. This involves a whole bunch of plots
> and variables printed to the screen (in-code) to aid in
> understanding how my changes worked.
>
> When I'm satisfied with a change, I then reactivate my loop,
> and see how things came out over all of my data sets.
>
> At this point I have a problem, as I end up giving myself
> epilepsy as all the plots and figure windows flick back and
> forth for each iteration of my data set loop.
>
> So, my question is, how would you guys normally get around
> this? Obviously, going over code and
> commenting/uncommenting any plot lines is a little
> tedious... perhaps I could encase all of my plot/debug lines
> in an if-statement, and then just toggle a variable at the
> top of my program to turn on/off printing.

One way to do this is to set the default value of the Figure Visible
property to 'off' before testing your code and turning it on afterwards.
This won't work so well if you need to print your figures in a format that
requires a screen capture or if you need to create a movie from them using
GETFRAME, but if not that's the first thing I'd suggest. Search the
documentation for "setting default properties" and you should find what you
need.

The second suggestion I'd make, if that's not acceptable, is to coordinate
coffee/bathroom breaks (or meetings, if your tests run for a long time) with
runs of your test. *grin*

--
Steve Lord
slord@mathworks.com


Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
editor Sven 19 Nov, 2007 04:25:06
debug Sven 19 Nov, 2007 04:25:06
rssFeed for this Thread

Public Submission Policy

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.

Contact us at files@mathworks.com