Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re: The joys of bad code

by TomDLux (Vicar)
on Oct 26, 2004 at 17:00 UTC ( #402710=note: print w/replies, xml ) Need Help??

in reply to The joys of bad code

Here's one I deal with at my present job. This isn't a mistake by an intern, but production code relied on by many people.

Instead of writing a module that you include into your code, system X was implemented as a program which reads in your code! You invoke it as system_X

Then system X reads in your file and evals it. But compilers don't know about comments, so comment lines are skipped:

# Read in configuration parameter file open (FILE,"<$scriptFile") || die "Cannot open $scriptFile"; while (<FILE>) { # Remove comments $script .= $_ unless /^\#/; } close FILE; eval $script; die "$@" unless $@ eq "";

Besides the foolishness of having things backwards, using eval on a string instead of on a file name means that when I debug code ( M-x perldb in emacs ), the system doesn't know where the source code is located and so cannot display it. But that wasn't enough for the villain who wrote this .... by skipping comment lines, the line number displayed by the debugger bears no relation to the actual line in the file.

But I have found a way to beat the system, considering I cannot change the basic system X files. My include file is short, and requires other files, which contain my actual code. So the eval reads in the files which contain my real code, and the debugger works. For debugging purposes, I have my own copy of system X which does not skip over comments, since the Perl compiler can handle that without my help.


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://402710]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (7)
As of 2017-01-17 20:37 GMT
Find Nodes?
    Voting Booth?
    Do you watch meteor showers?

    Results (158 votes). Check out past polls.