Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

In various integrated development environments, such as Microsoft Visual Studio, there is an integrated debugger where you can step through code sections, examine the state of variables and figure out where things are going wrong. With more complex Mathematica programs a debugger would be an extremely valuable asset. I was wondering what people use to debug Mathematica programs?

Is Wolfram Workbench the only/best solution?

share|improve this question
2  
Related, but not duplicate: mathematica.stackexchange.com/q/2230/8 –  Verbeia Feb 24 '12 at 5:47
    
How to use the built-in debugger: stackoverflow.com/a/8363520/879601 –  Chris Degnen Feb 9 '13 at 15:26

2 Answers 2

up vote 15 down vote accepted

I think you got 4 choices:

  1. Workbench. Probably the most useful of the debuggers.
  2. Mathematica has a small debugger: Evaluation -> Debugger
  3. There is DebugTrace from David (perhaps there are other packages)
  4. Use Print, Trace(Scan)[], etc type of functions.
share|improve this answer
    
SO Link on lower side of page there is mention of using Mathematica's built-in debugger. –  Rorschach Apr 12 '13 at 7:31

I found a curious style of debugging that I call "Epicsauce Debugging Level 2."

First you type this:

x = 0;
While[True,
  Pause[1];
  (*Dynamic[x]*) x++
];

Then you highlight the Dynamic[x] and press Ctrl+Shift+Enter. Then you execute the cell and BE AMAZED!!! It's quite hilarious, but I wonder how useful it would be for more serious code.

I've already been using this for some minor things, like to check that a value is actually being modified. The fact that you can place it right by the variable itself is conceptually significant, I think.

Edit: This is actually pretty cool. Here's one practical use. You know when you compose a bunch of stuff, like a graphics expression:

enter image description here

And then your script starts getting a little complicated, and you aren't even sure if the issue is with one of your small components or it's an issue with the final composition? Well you can do this:

enter image description here

Remember that's a live, rotatable object in the comment. One that auto-updates. The nice thing here is that you can debug individual components without breaking out of the flow of your program as a whole.

Edit2: You can highlight the line where the cuboid is being defined and hit Ctrl+Shift+Enter to only evaluate that line and not the whole expression, and see your changes in the comment. It appears that expressions that return Null (such as those ending with ;) aren't replaced when you Ctrl+Shift+Enter on them. Also remember that Ctrl+. will let you quickly select whole expressions.

share|improve this answer
3  
There is no need to "Excuse the necromancy" -- in fact there is a badge for posting late-but-good answers! –  Mr.Wizard Apr 13 '13 at 18:41

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.