Why put a debug option in a production code perl script?

G

grocery_stocker

In the following perl script snippet, the author has a debug option

sub main() {
my $dir;

error ("LANG is $ENV{LANG} -- UTF is no good, man!")
if ($ENV{LANG} && $ENV{LANG} =~ m/utf/i);

while ($_ = $ARGV[0]) {
shift @ARGV;
if ($_ eq "--verbose") { $verbose++; }
elsif ($_ eq "--debug") { $debug_p++; }
elsif (m/^-v+$/) { $verbose += length($_)-1; }
elsif (m/^-./) { usage; }
elsif (!defined($dir)) { $dir = $_; }
else { usage; }
}
usage unless $dir;
$dir =~ s@/+$@@;
if (! -d $dir) {
print STDERR "$progname: directory $dir does not exist\n";
usage;
}
build_index $dir;
}

main();
exit 0;

What's the point of shoving a debug option into a script that is
supposed to be used by other users?
 
X

xhoster

grocery_stocker said:
In the following perl script snippet, the author has a debug option
....

What's the point of shoving a debug option into a script that is
supposed to be used by other users?

You think that stuff that is supposed to be used by other users has no
need to be debugged?

Xho
 
U

Uri Guttman

gs> In the following perl script snippet, the author has a debug option

forget about the debug option, the code is nutso!

gs> sub main() {

don't use prototypes, especially for no reason.

gs> my $dir;

gs> while ($_ = $ARGV[0]) {
gs> shift @ARGV;

what a wacky way to loop over @ARGV. ever heard of foreach ( @ARGV )??
and his loop fails if ARGV has a '' or 0 value.

gs> if ($_ eq "--verbose") { $verbose++; }
gs> elsif ($_ eq "--debug") { $debug_p++; }
gs> elsif (m/^-v+$/) { $verbose += length($_)-1; }
gs> elsif (m/^-./) { usage; }
gs> elsif (!defined($dir)) { $dir = $_; }
gs> else { usage; }

ewww. not much more i can say about that.

gs> What's the point of shoving a debug option into a script that is
gs> supposed to be used by other users?

it would be harder to maintain 2 versions of the code, with/without
debugging options. if the real debug code isn't in the way or slows down
the program, this little debug option is not a problem.

uri
 
G

grocery_stocker

You think that stuff that is supposed to be used by other users has no
need to be debugged?

It hurts to think somedays. Today is one of those days.
 
J

Josef Moellers

grocery_stocker said:
In the following perl script snippet, the author has a debug option
[ ... ]
What's the point of shoving a debug option into a script that is
supposed to be used by other users?

Sometimes people complain that they have this or that problem when using
my code. I'd have several problems, then:
1. I'd have to spend additional time to produce a debuggable version
2. I may not be able to (re-)produce the exact version that person has
(this can most often be achieved by using a versioning system that's
worth its name, not everybody does that (blush))
3. The introduction of debugging code might change the behaviour of the
code and/or may even require some code to be rewritten to accomodate the
debugging code (a veryvery simple example might be when you directly
return a complicated expression and want to print out its value beforehand)
There are probably lots of reasons I can't think of.

So I can just tell them "retry with a -d option, redirect stdout into a
file, then send me that file".

MHO,

Josef
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top