Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language


 
 
Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

Perl Programming Language

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


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?

grocery_stocker <cdal@gmail.com> wrote:
> 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

--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB

>>>>> "gs" == grocery stocker <cdal@gmail.com> writes:

  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

--
Uri Guttman  ------  u@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org

On May 24, 1:15 pm, xhos@gmail.com wrote:

> grocery_stocker <cdal@gmail.com> wrote:
> > 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?

It hurts to think somedays. Today is one of those days.
grocery_stocker wrote:
> In the following perl script snippet, the author has a debug option

[snip]
>   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; }
>   }

[snip]

On a side note to what others have said, it would be better to use
Getopt::Long vs. looping through @ARGV.

--

Len

grocery_stocker wrote:
> 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
--
These are my personal views and not those of Fujitsu Siemens Computers!
Josef Mllers (Pinguinpfleger bei FSC)
        If failure had no penalty success would not be a prize (T.  Pratchett)
Company Details: http://www.fujitsu-siemens.com/imprint.html

Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc