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?


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.
  • $\begingroup$ SO Link on lower side of page there is mention of using Mathematica's built-in debugger. $\endgroup$ – Sejwal 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;
  (*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.

  • 7
    $\begingroup$ There is no need to "Excuse the necromancy" -- in fact there is a badge for posting late-but-good answers! $\endgroup$ – Mr.Wizard Apr 13 '13 at 18:41
  • 2
    $\begingroup$ Mind. Blown. How exactly was this discovered?? $\endgroup$ – ibeatty Nov 1 '17 at 16:50
  • 1
    $\begingroup$ I'd vote this up for "best hack of 2013" if there were such an award :) $\endgroup$ – Reb.Cabin Mar 11 '19 at 16:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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