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:
- Does it work?
- Can someone else come in, make a change, and be reasonably certain no bugs were introduced?
|