Tuesday, November 18, 2008

"Scripting" Languages and Utilities

OK, calling them "scripting" languages these days is a disservice. What I would traditionally call a scripting language is a language that doesn't require a compiled executable, is dynamically typed, has great string manipulation functions or classes, and has regular expression support. These days there are tons of choices, and most of them are full fledged languages with functional frameworks that can accomplish anything a compiled language can. This post is a summary of a recent experience with some "scripting" languages, and the cool tools I found to make the experience much more enjoyable.


I recently worked on two tasks that together put me in front of Python, Perl, and Ruby. I like it when I have a task that requires using any of these languages, but the problem is I dabble in them so infrequently that I often spin my wheels getting back up to speed. I fumble through old scripts stealing bits and pieces of code. I litter print statements here and there so I can tell what is going on. I basically revert to my freshman year of college in CS101 labs.


Now that I'm a "professional", however, at the first sign of trouble I started looking around for tools to help me figure out what was going on. My first dilemma centered around a Python script that was stopping at an unexpected error. I didn't write the script, I really needed it to work, and I don't know a thing about Python. What I really needed was a debugger to help me browse around the script and quickly understand the data structures it was using and what it was trying to do when it failed.


A command line debugger was not going to do the trick. I have no problem resorting to something like gdb or Perl's command line debugger when I really have to, but those debuggers are really at their best when the developer is already familiar with the script and has a bit of an idea of what they are up against. A visual debugger is a must when you are stepping through code for the first time and just trying to get a feel for what is going on.


A few web searches under my belt, and I was happy to find winpdb, a platform independent visual debugger for Python. The debugger was easy to use, and had a great watch window that not only showed local variables as they entered and left scope, but also correctly displayed control characters inside variables, which made debugging regular expressions much easier (click the picture below for a larger screen shot).




In a separate task this week I needed to write a script to clean up some "garbage" characters that our legacy help file authoring system was randomly placing in our HTML help. I chose Ruby for the task, as I had written quite a few Ruby scripts in the past and I really like the language. I ended up stumped on a regular expression never matching text that I thought it should (and I knew the expression was sound because I had already tested it in my editor). While I could have resorted to some "printf debugging", my Python debugger experience had me anxious to find a visual debugger I could use with Ruby in this and future projects.


Google to the rescue and soon I was debugging my Ruby scripts inside Visual Studio. This thing is brilliant! The screen shots below are from Ruby in Steel. Note the black background is my Visual Studio preference, not an oddity of Ruby in Steel. While Ruby in Steel is not free, it is very inexpensive and I'll be buying a license this week. Debugging my Ruby scripts in the familiar Visual Studio environment put a huge grin on my face. It felt like cheating.






The real kicker for Ruby in Steel was the intellisense. Since I don't use Ruby all the time, when I do start writing a script I find myself constantly referencing the documentation to find class methods. I love being able to type a class name, hit dot, and browse for methods without leaving the editor.




There are other .NET based implementations like IronPython and IronRuby which I imagine use the Visual Studio debugger as well, but for basic script debugging I found these utilities extremely useful.

No comments:

Post a Comment