Fog Creek Software
Discussion Board




Using a debugger for Perl or Php

I'm curious. I've seen people mention that they use a debugger for Perl. I saw a guy start a perl script in a debugger and he was a smart guy (had once worked at the JPL and he had just published a book) but I left the company before I ever asked him about it.  I've never used a debugger. I do Perl and PHP. I cannot imagine the use of a debugger for either of those languages. I wonder if I'm missing something that could make my life easier. Is it useful for code you have not written (the guy above was using it in this situation) ... for me I just do a syntax check for errors. Thanks.

meagain
Friday, June 11, 2004

perl -d

Now you are in a debugger.

son of parnas
Friday, June 11, 2004

PHPedit comes w/ a debugger.  It's usually easier to use print statements, but once in a while its a lifesaver. 

Lee
Friday, June 11, 2004

What I don't understand is what a debugger would give someone for Perl or PHP.  99.9% of the time if your script passes a syntax check it will run. Anything that is then "wrong" with it is something that I reckon you need to read the code in relation to the requirements.  I wonder if I have a script which includes other files as in OO or just modular then perhaps the debugger will load those ... but how does it spark events? And even then ... what can I really give me that I would not get from reading the code?

meagain
Friday, June 11, 2004

Well, part of me agrees with you. If you have absolute confidence in your understanding of a language (any language), why would you ever need a debugger? Just dry-running the code by eye should show you where the mistake is.

Specifically regarding Perl: I would say you have not yet written any large enough or complex enough Perl programs.

Ian
Friday, June 11, 2004

While acknowledging that one *shouldn't* need a debugger for PHP, I've used one and quite liked it.  As a previous poster said, occasionally it's a life saver.  Not just for syntax that won't compile -- the error messages that PHP spits out are usually sufficient for that -- but once in awhile to track down why some value isn't getting stuffed where you think it is.  I don't have a lot of experience with "traditional," compiled languages, but I would imagine the same argument could be made -- you can get by without a debugger, but heck, if it's there it ain't going to hurt.

BTW, I googled for some stand alone PHP debuggers that could be used with editors that don't include one but can work with a plugin debugger and found 2 or 3 that seemed sufficient... never got around to trying any of them though.

OffMyMeds
Saturday, June 12, 2004

Um, I've been writing Perl code for years now and I've *never* used the Perl debugger. How on earth does it help you?

Phalse
Saturday, June 12, 2004

Apparently you've never had to deal with less-than-perfect code written by others. The debugger is a godsend here.

Egor
Saturday, June 12, 2004

Even if you're the perfect runtime engine for a particular language debuggers are useful for running them v-e-r-y s-l-o-w-l-y.

So slowly that it gives you time to think 'Stupid Boy of course it fails'. 

Debuggers are also useful for capturing contextual errors, ie watchpoints set for when a variable or a state changes or gets a particular value.

This is a part of the discipline known as software engineering, which is almost entirely unlike programming save one regard.

Simon Lucy
Saturday, June 12, 2004

> How on earth does it help you?

The few times i have used it have been to figure
out where and why perl core dumped.  Other
than that i can get away with visual inspection,
printfs, and removing code until it works.

son of parnas
Saturday, June 12, 2004

Wow, discussions like this make me think there really are two kinds of programmers -- those that think they never make mistakes, and those that think they do occasionally make mistakes.

I typically use the debugger for unit-testing.  Especially in Perl, you can change variables on-the-fly to insure all possible paths through your subroutines are exercised, and that all results are what you want to have.

I know I can make mistakes, and that I may not have a perfect understanding of the computer language I'm using.  The computer will do what I told it to do, but did I tell it the right thing?  Walking through the code in the debugger lets me catch my incorrect assumptions, and gives me lots of warm fuzzies that I really do have it right.

I guess there is a large group of programmers (and managers, too) who assume running under a debugger has no purpose.  I don't know how they can continue to think this, with the "crisis in software engineering" we're always hearing about.

The other alternative I guess is writing trivially simple code, which you CAN examine by eye.  I do aspire to making my subroutines (you other people DO use subroutines in Perl, right?) as simple as possible.  I still never assume I never make mistakes.

AllanL5
Saturday, June 12, 2004

For the record i make plenty of mistakes. The
debugger doesn't help much in finding them
though. For unit testing i write explicit tests.
Changing values in a debugger is not adequate
testing in my book.

son of parnas
Sunday, June 13, 2004

Hey, I never said I don't make mistakes! I just don't see what on earth a debugger could offer you over print(), especially since Perl usually gives you nice, descriptive error messages, and with a few debugging print()s sprinkled about, it's not hard to find most bugs.

Phalse
Sunday, June 13, 2004

Fair enough.

Before I had nice visual debugging environments, I used WRITELN and 'printf' statements for debugging.  I had assumed that was 'old technique'.

Recently I've started doing more embedded stuff, and using serial output to send messages turns out to be very useful -- so I certainly see the value in the 'printf' statement. 

I also see the value in more 'formal' unit-test procedures.  However, the original question was, "why use a debugger at all", and I think I've answered that.

AllanL5
Sunday, June 13, 2004

*  Recent Topics

*  Fog Creek Home