in reply to Re: Perl Programming guidlines/rules
in thread Perl Programming guidelines/rules

At my company, we were on the verge of hiring a particular programmer. I wasn't too fond of the guy, but his code looked okay. My boss thought he was great and since I was willing to sign off on his code, he was probably going to get offered the job.

He was still bugging me, though. There were a few things about his code that just didn't belong there and I was struggling to figure out how someone who clearly knew Perl had such obvious pieces of cruft in his code. Some of it was a useless "ref $proto or $proto" line in a constructor. Some of it was an AUTOLOAD function that allowed the programmer to create accessors and mutators from object properties that didn't always exist. It was confusing.

Then we got lucky. Perhaps he was afraid he wouldn't get the job, but he followed up with another code sample. It was also good code, but it had the exact same problems as the first code sample he sent. That's when I realized what was going on. I knew some people at his previous company and made some calls. I was right. This guy was using code templates and just blindly followed them. The templates provided a generic constructor and AUTOLOAD. Rather than thinking about what he was doing, he was just blindly following orders.

No offense, but your code template would be horribly inadequate for a template for me. What about warnings? What about taint checking? What if I'm running under mod_perl and need to use the OO CGI interface (you mostly use that, but you have ":standard" in your import list).

There may be acceptable code templates out there and I'm not opposed to them, per se, but they should be used with thought and caution.

Cheers,
Ovid

New address of my CGI Course.
Silence is Evil (feel free to copy and distribute widely - note copyright text)

Replies are listed 'Best First'.
Re: Re(2): guidlines/rules (Don't use code templates!!!)
by John M. Dlugosz (Monsignor) on Nov 21, 2002 at 19:59 UTC
    That sounds similar to what I call a "wizard's apprentice" in Microsoft Visual C++. I've interviewed people who can't write a class, but claim to code C++.

Re(3): guidlines/rules (Don't use code templates!!!)
by dingus (Friar) on Nov 22, 2002 at 08:52 UTC
    No offense, but your code template would be horribly inadequate for a template for me. What about warnings? What about taint checking? What if I'm running under mod_perl and need to use the OO CGI interface (you mostly use that, but you have ":standard" in your import list). My template was meant as an example of what you could do - it was known to be incomplete and/or wrong. I hacked it in about 2 minutes from the one I do use to make it begin to correspond to the style that the original poster wanted.

    Just to make it clear: ANYONE WHO USES IT AS IS STUPID BECAUSE ITS INCOMPLETE AND PROBABLY BROKEN

    As you noticed it has some OO inconsitencies. This is because I don't use mod_perl, tend not to OO my CGI scripts, and I failed to completely convert to OO.

    There may be acceptable code templates out there and I'm not opposed to them, per se, but they should be used with thought and caution.

    100% agreement - see more comments below

    This guy was using code templates and just blindly followed them. The templates provided a generic constructor and AUTOLOAD. Rather than thinking about what he was doing, he was just blindly following orders.(My emphasis)

    Templates are there to get you started. Slavish devotion to a template, like slavish devotion to rules or anything else is always a problem. Neither templates nor rules will make a barely competant programmer into a genius, but a template can help the next guy figure out what dumb error Mr lowgrade bozo just committed.

    A template like the one I suggested makes it relatively easy to generate test cases and to break down the action into separately testable chunks. As someone who has spent much time debugging other people's crud, this kind of inbuilt modularity and testability I wish to encourage, hence my template.

    Dingus


    Enter any 47-digit prime number to continue.