Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Worst thing you ever made with Perl

by thelenm (Vicar)
on Sep 29, 2003 at 16:41 UTC ( #295032=note: print w/replies, xml ) Need Help??


in reply to Worst thing you ever made with Perl

When I was first learning Perl, what I had to look at was a very early version of what later became Slash. I'm not kidding, it was horrible (but I didn't know that then). I can say without hyperbole that what I created as a newbie geek, using that as a base, turned out to be about a billion times worse.

Have you ever played a game called Assassin? Basically, there are N people playing the game, and each person has the name of someone else in the group that they are supposed to "kill". No one knows who has which name. Once you kill someone, your next assignment is to kill the person they were supposed to kill. The last person left alive is the winner. The way we played it in college, you could "kill" someone by shooting them with a water gun, with various caveats such as "you can't shoot someone while they are in class or in their room". Oh yeah, and you can also get killed by specially-appointed "Mafia" if you're taking too long to kill your own victim. This game tends to induce massive paranoia.

Anyway, I wrote a little CGI program to generate the assassination assignments, allow players to log in and register their kills, keep track of the current status of the game, allow discussion in the "morgue" among all the players who had been killed, etc. I was really proud of it, and it actually ran pretty smoothly, with a few minor problems (such as never checking for HTML in posts, which allowed the more technically inclined dead players to do all sorts of clever things in the morgue).

I hadn't looked at the code in about five years, but just last week I came across it again. I laughed out loud several times at what I had done. There were hundreds of hardcoded (and frequently duplicated) strings and numbers. Global variables galore. And just about every subroutine (at least I had subroutines!) had something like this in it:

                ($u,$p,$f,$l,$n,$e,$a,$y,$s,$r,$v,$td,$i,$m,$t,$lo,$c,$k,$pt,$lg) = split(/\n/,$_);

... of which only one or two of those variables were used. But sometimes they were all used, and heaven help you if you wanted to figure out what $pt or $m is supposed to represent. A couple of guys wanted to add some more features to the code after I left, so I let them have it. They kept emailing with questions like, "Hey Mike, do you remember what $tdh does in the subroutine findMyData? It's the one between $p and $yo." I feel bad for those guys.

If I were to do it differently? I'd use variables with meaningful names and small scope. I'd eliminate duplication and magic numbers/strings. I'd use the CGI module. I'd write subroutines of fewer than 1000 lines. And I'd ask to look at some code other than CmdrTaco's. :-)

-- Mike

--
XML::Simpler does not require XML::Parser or a SAX parser. It does require File::Slurp.
-- grantm, perldoc XML::Simpler

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://295032]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2020-11-26 19:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?