The Artima Developer Community
Sponsored Link

Agile Buzz Forum
That old "it works in the debugger" feeling

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
James Robertson

Posts: 29924
Nickname: jarober61
Registered: Jun, 2003

David Buck, Smalltalker at large
That old "it works in the debugger" feeling Posted: Nov 5, 2005 11:43 AM
Reply to this message Reply

This post originated from an RSS feed registered with Agile Buzz by James Robertson.
Original Post: That old "it works in the debugger" feeling
Feed Title: Cincom Smalltalk Blog - Smalltalk with Rants
Feed URL: http://www.cincomsmalltalk.com/rssBlog/rssBlogView.xml
Feed Description: James Robertson comments on Cincom Smalltalk, the Smalltalk development community, and IT trends and issues in general.
Latest Agile Buzz Posts
Latest Agile Buzz Posts by James Robertson
Latest Posts From Cincom Smalltalk Blog - Smalltalk with Rants

Advertisement

Back when I was a C programmer, I ran across the "but it works in the debugger!" problem more than once - which usually meant that a buffer was being torched in normal runs, but the debugger was masking that problem.

Well, Steve Wessels points out a similar type of issue in Smalltalk - you can fool yourself with lazy accessors:

So you single-step through your code with the debugger. Here's the rub. When you get to where the debugger is showing your object in it's inspector or text pane, it's going to use the #printOn: method to show the object. This #printOn: method uses a combination of accessors and lazy initialization to show the contents of the object. But in the real code, real time, when your application was producing the report, let's say that the "time" instance variable had not been instantiated. It was still nil. In the world you think you are debugging the object was nil. In the context of using the debugger that instance variable got instantiated while you were single stepping the debugger.
Something like Heisenberg Uncertainty. You changed the object while looking at it.

For those of you who don't know, a lazy accessor looks something like this:


time
     ^time isNil
          ifTrue: [time := Timestamp now]
          ifFalse: [time]

The idea is to ensure that the variable is never in a bad state - but, when you are debugging that particular method, you can end up with surprises. Lazy accessors have their uses - I use them in the blog server, mostly because I update the server on the fly with new code - and I want to make sure that new objects (i.e., instance variables that didn't exist at all before I updated the server) are in the right state. Steve points out that you can fool yourself with this stuff though.

Read: That old "it works in the debugger" feeling

Topic: And we'll do one more Previous Topic   Next Topic Topic: What could suck worse than Office?

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use