Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

(OT) What Was Your Most Bone-headed Programming Error?

by Wally Hartshorn (Hermit)
on Oct 20, 2003 at 22:11 UTC ( #300778=perlmeditation: print w/replies, xml ) Need Help??

Recently, I was writing a Perl program that would, among other things, take some poorly-formatted phone numbers and pretty them up for display. We can dial internally using just the last 5 digits of the phone number. So, if I have a co-worker with the number "785-1234", I can just dial "5-1234" to reach him, while to reach "524-9876", I just dial "4-9876".

Because of this, many of the phone numbers in the input data were missing the leading 2 digits (not to mention the area code). We have a limited number of internal prefixes, so it was easy just to create a little hash to match up the missing digits with the 1-digit version abbreviations:

my %full_prefix = ( 78 => "5", # 785-xxxx 52 => "4", # 524-xxxx 78 => "2", # 782-xxxx );

You've already seen the problem, haven't you? I didn't. I fiddled with the cursed program for 20 minutes, trying to figure out why none of my tests were passing, before it finally occurred to me -- I had the keys and the values on the wrong sides! Doh! (*bang head on keyboard*) In splitting the numbers into the first two digits and the third digit, I forgot to swap them around.

So, to help me feel better about my obvious inability to handle even the most basic of Perl programming tasks, what was the most bone-headed programming error you ever made? I'm not talking about basic things that you didn't realize when you were just starting out. I'm thinking of things that you knew but somehow completely goofed on.

Please, make me feel better!

Wally Hartshorn

(Plug: Visit JavaJunkies, PerlMonks for Java)

Replies are listed 'Best First'.
Re: (OT) What Was Your Most Bone-headed Programming Error?
by vek (Prior) on Oct 20, 2003 at 22:22 UTC

    How timely. Here's today's little gem:

    sub _archive { my ($self, $store_file) = shift; # rest of code... }
    -- vek --

      Not to forget its one true friend:

      sub blah { my $arg = @_;




      I'll second this. :) I do it all the time too. The next most frequent one for me is forgetting to put "?" into regexp and then wondering why nothing was left of the input. ;)
Re: (OT) What Was Your Most Bone-headed Programming Error?
by tilly (Archbishop) on Oct 21, 2003 at 01:04 UTC
    How about accidentally accessing the wrong variable, that got passed into a shcll command run by some bad code on another machine?

    The end result was that rather than limiting which files got transferred to Bloomberg's ftp site, every file that they had ever been sent was resent. This was rather more than the receiving machine was prepared for, leading to crashing the machine which they use for receiving updates from partners.

    The most that I can say to defend myself is that none of the programs involved were originally written by me, nor was I responsible for the overall fragile architecture. (It was just my job to keep things going and improving.)

    The worst that I can say about this mistake is that while would have caught it, this was not the incident that convinced me to use (But I should hasten to note that this was back in 5.003 when foreach my $foo (@list) was an illegal syntax. Which made much more annoying to use than it is now.)

Re: (OT) What Was Your Most Bone-headed Programming Error?
by Ovid (Cardinal) on Oct 20, 2003 at 22:30 UTC

    If you're in a position to hire or recommend anyone, please do not read this :)

    My worst blunder was something like this:

    my $sth = $dbh->prepare(<<' END_SQL'); UPDATE product_people_currency SET people_id = ? WHERE people_id = ? END_SQL while (my ($old_id, $new_id) = each %id_pair) { $sth->execute($new_id,$old_id); }

    Naturally, the new id happened to match several old ids and the program happily reupdated them. However, because all IDs were valid, all of the tests passed and we ran this snippet against a production database. Our clients saw that the web site was still up and informed us that the "update" worked fine. It was weeks of bad emails going to their product contacts before they realized that it was the web site that was messed up.


    New address of my CGI Course.

Re: (OT) What Was Your Most Bone-headed Programming Error?
by graff (Chancellor) on Oct 21, 2003 at 07:45 UTC
    My dumbest mistakes tend to be in C rather than Perl, e.g.: a tool I wrote some time ago to do simple statistics on digital audio files (8-bin histogram of 16-bit sample values) worked just fine on my sparc, so I put it on a linux box, checked about 30 GB worth of audio files, found them to be "bad" (histograms were just too wacky), and so I deleted those files. (I was trying to validate a particular processing pipeline, and I concluded that something must have gone wrong with the process.)

    Then I noticed that when the code detected the byte order of the 16-bit data, it was byte-swapping to big-endian when necessary, in order to get the numbers right -- on the sparc (which made them wrong on i686-linux). Oh well, it would only take a day or so to reconstitute those files... so the delivery would only be that much behind schedule.

Re: (OT) What Was Your Most Bone-headed Programming Error?
by Wally Hartshorn (Hermit) on Oct 21, 2003 at 15:10 UTC

    Here's a couple of more that I remember.

    When I was in college (back in the early 1980's), we were programming on a mainframe computer. When you compiled a program, it would generate a compile listing, which would contain the source of your program along with error messages. The compile listing would be displayed within the text editor. (You can see what's coming, can't you?) On more than one occassion, I would be looking at the compile listing, see my problem, make the correction to the source within the compile listing, and then be mystified as to why the problem was still there when I recompiled.

    The other one that I remember involved setting some values in a hash, then trying to retrieve those values and coming up empty. The problem was, when the values were being set, the keys were ALL-CAPS, but when we were retrieving them, the keys were lower-case. I was pair-programming with someone and to this day, whenever we make a bone-headed programming mistake, we look at each other and say "Hashes are case sensitive!"

    Wally Hartshorn

    (Plug: Visit JavaJunkies, PerlMonks for Java)

      Your JavaJunkies looks nice. Out of curiosity, have you approached Sun to be your sponsor? It seems like it would interest them. Maybe they would give you your fast server.
Re: (OT) What Was Your Most Bone-headed Programming Error?
by hardburn (Abbot) on Oct 21, 2003 at 13:56 UTC

    Not strictly programming, but closely related:

    I was working on the Everything Over Freenet project (now pretty much extinct) and was using CVS for the first time. I forgot to cd into my project directory and instead managed to import a significant chunk of my home dir onto SourceForge before I realized what I did. Naturally, this included my GnuPG keys. Then I got to find out how painful it is to attempt to delete files from CVS.

    I wanted to explore how Perl's closures can be manipulated, and ended up creating an object system by accident.
    -- Schemer

    :(){ :|:&};:

    Note: All code is untested, unless otherwise stated

Re: (OT) What Was Your Most Bone-headed Programming Error?
by JPaul (Hermit) on Oct 21, 2003 at 13:56 UTC
    I had one of those moments about two days ago where you have an error so confusingly dumb you just know you've done something stupid, and when you do find it you know you'll kick yourself.

    I keep two development enviroments for a chunk of web software I've been working on, one locally and one remotely on the company dev server.
    I'm working on my local copy (faster SSHing) and change a very simple feature, it was something related to what a function printed back out into the HTML, and I set the monster running - and nothing. No changes.
    I go and look at the code again... Confused. So I stick a 'print STDERR "Value $var\n"' in there, to make sure my var is what I expect it to be, run the CGI again via the browser... Nada. Nothing in the error log. I think about this for a bit and decide that, yes, I've done something really dumb.
    I just can't see it. I don't get it... So, I walk away for 15 minutes and take a break.

    Return. Think. Think. Look at the access logs - and its not even being touched?
    Decide I'd better double check the URL... Sure enough. I had somehow switched over accidentally from the local copy to the dev copy I hadn't been working on.

    So banal when you work it out. So damned frustrating when you're right there wondering what kind of moronic cock-up you've just made.

    -- Alexander Widdlemouse undid his bellybutton and his bum dropped off --

Re: (OT) What Was Your Most Bone-headed Programming Error?
by menolly (Hermit) on Oct 21, 2003 at 16:17 UTC

    My brain is apparently blocking my own dumb errors, though I know I've made some, but none of mine top one from a predecessor at a former employer, a major PC manufacturer.

    There was a subroutine which was supposed to adjust prices on certain items in certain circumstances; something to do with government contracts and pricing to the .1 cent level (yes, 1/10th of a cent).

    Well, someone bozoed, something like = instead of += or adjusting the wrong variable, and was setting the price to a tenth of what it should be. And this somehow made it live. The "fix", which was in place when I came in, turned the whole subroutine into a no-op, by modifying one local variable and returning a different one.

Re: (OT) What Was Your Most Bone-headed Programming Error?
by tbone1 (Monsignor) on Oct 21, 2003 at 19:46 UTC

    I've written some doozies in C, though luckily none when I was touching the phone company's 911 system. As for Perl, one in particular stands out. When I was new to Perl, back in the days of Perl 4, I was testing a script in the same directory as the test data. (I know, I know, but if you knew how hard I'd had to fight just to get test data, ...) The script was to take a HUGE list of files and, based on the file names, place them into new subdirectories. An ideal job for Perl, right?

    Anyway, after the script ran, I was left with some files that were the result of directory handles. (Like I said, i was new to Perl at the time.) This wouldn't do on one of NASA's public ftp sites, so I had the Perl script delete any leftover non-directory files ... which, in the test area, included the Perl script that was running.

    So yes, I have written self-deleting code.

    Ain't enough 'O's in 'stoopid' to describe that guy.
    - Dave "the King" Wilson

Re: (OT) What Was Your Most Bone-headed Programming Error?
by Jenda (Abbot) on Oct 22, 2003 at 13:30 UTC

    A few years ago I needed to merge two directory trees with some pictures (don't ask ;~). There were some duplicates, some files that were only in one or the other tree, some files that had the same name but different content and so forth. So I started with a script that was supposed to browse those two trees and delete the real duplicates. Well ... gues what ... I inverted some condition by accident and started deleting the UNIQUE files. Oh my ... I did succeed to undelete some of the files, but quite a few have been lost :-(((

    Such things really teach you to test things first :-}

    P.S.: (Not Perl related and not really dumb ... or maybe yes, who knows.) A friend of mine was writing some school project in Pascal with TurboVision. And the program kept printing an error message "Null pointer assignment" when it was exiting. Some object was destroyed too soon or whatever. He could not find the error no matter what so he solved it differently. He made the program print "Made by " just before closing ;-)

    Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.
       -- Rick Osborne

    Edit by castaway: Closed small tag in signature

Re: (OT) What Was Your Most Bone-headed Programming Error?
by delirium (Chaplain) on Oct 23, 2003 at 12:28 UTC
    I've made a few doozies myself, but the worst I've encountered was one that I was a victim of, which, but for my silver tongue, would have got me fired.

    I worked in a call center that used an Aspect phone system. After working there for about 6 months, the Aspect programmer (who ran reports for management) and my manager approached me.

    "Curtis, do you just never call any of your customers back?"

    "Of course I do, what's this all about?"

    After a little while of pleading my case, I got the programmer to run a custom report on all my call data without filtering anything, where my stats then looked the same as everyone else's.

    As it turns out, our phone system let you omit the "1" on a long-distance call, which I figured out in my first week, so I was happily dialing one digit less on all my outbound calls. The programmer, who generated the reports on which some portion of an employee's job performance was determined, was grepping for phone calls in the database that matched a fixed length - 12 digits (9,1,then the 10 digit number).

    That was quickly fixed, and it was determined that calls to local companies and international calls had never been considered in the past, either. However, I was the *only* employee to ever not dial a 1 for a long distance number. To help rectify that, I made sure to mention the shortcut dialing method to all of the new hires classes I trained.

Re: (OT) What Was Your Most Bone-headed Programming Error?
by Anonymous Monk on Oct 20, 2003 at 22:20 UTC
    Hasn't this been done before?
      It has, but good meditations are often revisited (not too often tough, once a year is enough).

      MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
      I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
      ** The third rule of perl club is a statement of fact: pod is sexy.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlmeditation [id://300778]
Approved by Ovid
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2023-10-03 00:08 GMT
Find Nodes?
    Voting Booth?

    No recent polls found