Re: Coding inside the debugger

From: Phlip (phlip_cpp_at_yahoo.com)
Date: 08/23/04


Date: Mon, 23 Aug 2004 05:00:42 GMT

Thomas Gagne wrote:

> Phlip wrote:

> > Thomas Gagne wrote:
> >
> >
> <snip>
> >
> >
> > Why the heck not? TDD leads to very aggressive decoupling, so those
details
> > are separate and exposed to tests.
> >
> How would a unit test inspect the state of a temporary variable?

By detemporalizing it?

> I don't disagree with that, but eventually you do write code, don't you?
> After you're finished writing a unit test (which itself is code) you
> eventually write some program code, right? Have you ever tried doing that
> inside the debugger? It's fun! Or at least I think it is.

Unit tests are an excellent platform for using a debugger.

I TDD, these days, on two platforms. One uses C++, WTL, COM, MSXML, and
Sanskrit. The other uses Ruby, REXML, GraphViz, and TkCanvas.

The VC++ platform has a full-featured integrated debugger on which I have
>10 years experience, and I use it freely. The Ruby platform I'm certain has
a debugger, but I have not yet once in my life ever used it, and I never
will. I edit Ruby using Scite, which supports simple edit commands the same
as VC++, and can execute the current script on <F5>.

My velocity, and defect rates, in both platforms, are comparable.

Without a debugger, one uses trace statements. My VC++ trace statement is
the most sophisticated one in this industry:

    #define db(x_) do { std::stringstream z; \
            z << __FILE__ << "(" << __LINE__ << ") : " \
                    #x_ " = " << x_ << endl; \
            cout << z.str() << std::flush; \
            OutputDebugStringA(z.str().c_str()); \
            } while (false)

That takes any argument, including expressions, which support operator<<,
and it reflects that source's expression using the # stringerizer operator.

db(q) pushes "C:\path\source.cpp(99) : q = 5\n" into the Output Debug panel.
<F8> parses the file name and line number and navigates your editor directly
to the line containing the db(q). Put another way, my trace statements can n
avigate my editor directly to their source.

Amazingly, when I perform light debugging of a sticky situation in Ruby, I
have not yet bothered to put my equivalent trace statement online for my
current project. My Ruby trace statement attempts the same things as my C++
one:

def trace_(&b)
        file, line_nr, funkshun = caller()[0].split(':')

        funkshun = funkshun.split('in `')[1]
        funkshun = funkshun.split("'")[0]
        line_nr=line_nr.to_i
        linecnt=1
        expr=nil

        File.open(file).each_line do |line|
                if linecnt==line_nr
                        if line =~ '(^|\W)trace_\s*{\s*(.*?)\s*}'
                                expr = $2
                        end
                        break
                end
                linecnt+=1
        end

        if expr
                puts "(#{line_nr})#{funkshun} #{expr}: #{eval(expr,
b).inspect}"
        end #{file}
end

It attempts to reflect its source into its output, like db() did.

But I have not used that in years. Nowadays, I debug my Ruby using its
built-in method p(), which is Ruby's debugging statement. And for
Intellisense, I have a little jigger that prints out all of an object's
non-standard public methods:

    def doc(anObject)
        puts(anObject.class.name)

        itsMethods = anObject.public_methods() -
                                        Object.new().public_methods()

        puts(itsMethods.sort()) if !itsMethods.nil?
    end

That works great for learning about the methods of some ornery undocumented
object that wraps an object written in some dead language.

TDD doesn't prevent debugging. It prevents, as a powerful emergent force,
those long open-ended multi-week bug hunts that destroyed schedules so
reliably.

-- 
  Phlip
  http://industrialxp.org/community/bin/view/Main/TestFirstUserInterfaces


Relevant Pages

  • Re: Debugging a multi-threaded application
    ... and we're now porting applications from CE 3.00 to CE 4.2. ... I am using eVC++ 4.0 and the debugger that it supports. ... using the debugger in Platform Builder. ...
    (microsoft.public.windowsce.platbuilder)
  • Re: PHP IDE or PHP editor
    ... My platform is Windows XP. ... An editor without a debugger is like a car without wheels. ... >> increadible debugging and code analysis features. ...
    (comp.lang.php)
  • Re: Anyone get the Arachno Ruby debugger working?
    ... I can't get the debugger to work. ... Ruby version downloaded from Arachno Ruby website (Scriptolutions ... I also tried Archono' one-click installer but it did work quite as ...
    (comp.lang.ruby)
  • Re: Connectivity problem with PB 5.0
    ... Debugger service map is set to none. ... The Kernel Debugger has been disconnected successfully. ... This appened when I create a platform with "Via ProSavage/Twister CEPC" ... NK.bin run correctly but operative system don't start. ...
    (microsoft.public.windowsce.platbuilder)
  • Ruby simple browser base source level debugger
    ... I recently start to develop a ruby source level debugger with ... small foot print and easy to install and use. ... At this release, no multithread support, no source file edit ...
    (comp.lang.ruby)