Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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


In reply to Re: Worst thing you ever made with Perl by thelenm
in thread Worst thing you ever made with Perl by Juerd

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2024-03-29 14:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found