Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Learning by debugging...

 
Pauline McNamara
Sheriff
Posts: 4012
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
...and by digging into someone else's code. That Aha! feeling is so nice.

I've recently dusted off the jdbc-4 assignment, which got me delving into a bunch of other stuff that I'd long forgotten (not the least of which is simply installing and configuring stuff). Last night I was still working on getting the jdbc-3 instructor's solution working.

Being the plodder that I am, I had retyped most of the classes, just to force me to look more closely at them and get back into the java syntax mode. That of course opens me up to all kinds of stupid little mistakes. Fortunately the compiler saved me from most of those.

But then there was something not working (an SQL INSERT didn't seem to be taking hold) and I was running out of ways of tracking what value was where. That's because the exception messages weren't showing up right in the app like before, there was a Nifty New Way in the instructor's solution. Or maybe it wasn't new, but I hadn't bothered to look into it before. So I went off on the sidetrack of finding this mysterious log with those all important hints about what was going wrong.

First I went to the com.javaranch.common docs. Got a nice description of what the mystery method was doing, but not all the gory details of how it worked. Time to dive into the source.

And such nice source it is. Paul's code and comments give you the picture quick - you see what's going on and how it works right away, no need to decrypt secret codes. So I found out there's a little switch you have to turn on. First I tried turning it on in the wrong place. Then I thought a little harder about what the comment was telling me. The second try worked and bingo, I had the caught exception displaying it's clue. Actually, it spelled it out really clearly and took only a minute to fix.

Yeeha! I'd found and fixed the problem! And it won't be a process that I'll forget anytime soon. That's the cool thing I guess I've been getting at. Debugging is a great way to learn. Not to mention working with code written by someone else. Especially if that code is com.javaranch.common.

Oh, almost forgot. The problem was a misplaced ' in the sql statement. Which proves that choosing to type instead of copying and pasting was *not* a bad idea: without that typo, I'd have missed out on all the other fun.
 
Carol Murphy
village idiot
Bartender
Posts: 1202
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pauline, I totally agree with you. Knowledge sticks better when I really have to take something apart to figure out how it works. (Or doesn't work, typically!)
So, since the assignments have been re-worked, are they really different?
Maybe if I find time I should go back and re-do some just to see if I can!
 
Marilyn de Queiroz
Sheriff
Posts: 9059
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have learned a lot by looking at other people's code in detail.

I think the new version of the servlets/jdbc assignments are significantly different.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic