in reply to Re: The trap of reference numification
in thread The trap of reference numification

It isn't that $row is bad in some way. It really was supposed to be an ARRAY ref. I just used the wrong variable. The one I wanted was $line_num.

Also, this is hardly the first time I've been bit by numified references. I say we should solve the problem, not swat at the symptoms.

-sam

  • Comment on Re^2: The trap of reference numification

Replies are listed 'Best First'.
Re^3: The trap of reference numification
by dragonchild (Archbishop) on Nov 11, 2005 at 23:01 UTC
    Sounds like you needed Hungarian notation. Not the evil Systems notation, but the good Apps notation. Refer to http://en.wikipedia.org/wiki/Hungarian_notation for more info on the difference. FWIW, the inventor invented the Apps version, but it was mutated into the Systems version due to a poor choice of words in the original whitepaper.

    My criteria for good software:
    1. Does it work?
    2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?
      That sounds like a cure that's worse than the disease to me. I'd prefer a less pathologically magical Perl over code full of prefixed variable names.
        Instead of:
        my $COMMIT_CHUNK_SIZE; my $line_num; my $row = [ ... ];
        Apps Hungarian would say to use something like:
        my $cnt_COMMIT_CHUNK_SIZE; my $cnt_line_num; my $db_row = [ ... ];
        (I completely made up the prefixes. They're there just to point out how one could do it.)

        Now, when we rewrite the snippet samtregar posted, it's immediately obvious that it's wrong.

        if ($db_row and ($db_row % $cnt_COMMIT_CHUNK_SIZE == 0)) { $dbh->commit; }
        You're having a $db_ and a $cnt_ variable interact without some sort of mediation. That's an obvious and inspectable red flag. In fact, when using Apps Hungarian, people have reported an inability to make these kinds of errors. It's kinda like Perl makes it really really hard to have dangling pointers. You can still do it, but you have to intentionaly disregard your best judgement to do it.

        My criteria for good software:
        1. Does it work?
        2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?