|Do you know where your variables are?|
Re: Improve readability of Perl code. Naming reference variables.by stevieb (Canon)
|on Jan 19, 2017 at 20:24 UTC||Need Help??|
This is one of the many benefits of keeping your code blocks (scope) as small as possible (one screen if possible), as it allows you to visually see what you're dealing with in regards to a variable.
To further, variable naming is important, as is attempting to write your subroutines so they only do one thing, as opposed to a whole bunch of things. This:
... is far too much typing just for visual purposes (imho), and it adds unnecessary noise. It's just as easy to scope properly and name things appropriately:
That's singular, so I'd put money on the fact it's a scalar (unless it's an object, but if it's an object, it'll be being used much differently than a simple scalar so I digress).
Both of those are extremely easy to identify to even a low-intermediate Perl hacker as an array reference in the former case, and a hash ref in the latter (perhaps the author has a hash of cat names to cat colours ;).
What's more, if there is confusion, in decently laid out code, one may have to scroll up only a tiny bit (if at all) to see where the variable is being declared/defined. If you have to search all over the code for where variables are defined, the scope for that variable is not small enough.
Even if you get the type wrong, with use strict; and use warnings; will always let you know the what/where of the problem.
So, in essence, I understand what you're desiring here, but good coding practices alleviate us from (for the most part) needing such visual cues.