Subscribe to Macosxnerd101's Blog        RSS Feed

Spock to Sulu: Use the Debugger

Icon 4 Comments
I had a moment today at work that reminded me of the episode Who Mourns for Adonis in the original Star Trek. In this part of the episode, Spock is on the Enterprise trying to track down the generator Apollo uses to power his godlike abilities. Sulu reports that he cannot locate the generator, so Spock directs him to search the entire planet region-by-region to locate the generator based on knowing where it isn't.

As many of you who have worked with Android (no, not Data or the Borg) are aware, the good ol' fashioned method() of using System.out.println() calls to debug doesn't work. The console is useless for that, so last summer I had to learn to use a debugger, and I must say I was impressed with Eclipse's debugger. I can get a good feel for the states' of the variables with it and step through my code. My coworker, who has been working with Android far longer than I have, had never used the debugger much to my surprise. It was very useful in quickly determining where the bugs originated by setting breakpoints to narrow the search radius down. In other words, we found bugs by finding where they weren't. And a lot of these bugs were his misunderstandings about how my code functioned. Most of my code was well commented from last summer, but I hadn't updated the comments much when doing some refactoring to go with the updated design, which is something I should have done as well.

Moral of the story- listen to the inner Vulcan in you when coding. Live long and prosper.

4 Comments On This Entry

Page 1 of 1

Curtis Rutland 

01 July 2011 - 12:35 AM
One day, you might try out C#, and you'll find that Visual Studio's debugger is simply incredible. You can set breakpoints, tracepoints, conditional breakpoints (as in, it'll only break on a certain condition, super useful for debugging in loops), etc...

You can set watches, but you can also modify the watch to evaluate an expression, which is really nice. You can actually modify the values in memory so you can quickly test what would happen if that were set.

You can step into, step over, run to cursor, all kinds of things. And in 2010, they added IntelliTrace, which is even more helpful.

Seriously, I didn't used to use the debugger either. I would put Console.WriteLines (C# for System.out.println) all over the place. But learning the debugger changed the way I program forever.

Also, if you ever find yourself writing Javascript one day, you can actually debug that with breakpoints and watch expressions in Chrome, if you Inspect Element and go to the Scripts tab. The browser has a built in debugger.


01 July 2011 - 03:33 AM
I need to try that. Right now, I have a whole bunch of Log.d()'s and frankly, it's a little difficult to figure out - especially with the numerical computing that I am doing, where floating precision can mess me up to no end. I will give the debugger a shot to see what I can do.


01 July 2011 - 06:12 AM
Adding to you're code, can change its behaviour and change what you're attempting to debug.


02 July 2011 - 12:08 PM
@Curtis: I'll keep that in mind! My laptop for college should be hear Tuesday, so I might get Visual Studio setup!

@Dogstopper: Definitely! It's worth it. I still prefer the old System.out.println() way for vanilla Java. For Android, the debugger is much better.

@Adam: Neat! I think Chrome has a similar feature with client-side code for debugging. I remember it when doing some web work a couple years ago.
Page 1 of 1

May 2022

151617181920 21

Recent Entries

Search My Blog

2 user(s) viewing

2 Guests
0 member(s)
0 anonymous member(s)