in reply to Re: Generating report on variables and alike...
in thread Generating report on variables and alike...

This might be nice. If it's not already there somewhere, it would be great to have useless variable names like %data or rampant single letter names flagged as sub-optimal.

Replies are listed 'Best First'.
Re^3: Generating report on variables and alike...
by dragonchild (Archbishop) on Apr 21, 2008 at 10:25 UTC
    Except as loop indices or as part of mathematical functions such as if ($x^2 + $y^2 == $z^2) { ... }. And, useless variables are only useless outside of context. %data might be perfectly acceptable in a properly-named function.

    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?

      I think the same kind of context heuristics used for single letter names could be extended to names like %tmp, %arg, and %data (or reaonsable single letters for cases like $c/$f/$k in a temperature sub). Check their scope. They are pretty reasonable in a small loop but I'd argue that in a main:: space or a block/sub longer than...? 10? lines, they could be named better and a critic rule might suggest that. Normally when I find myself using that kind of name it's out of haste and I wouldn't mind an automated kick in the pants to make me stop for 90 seconds to think about how it will really read to the next hacker (or to me in 6 months).