|No such thing as a small change|
Re: Perl Best Practices for naming variablesby mascip (Pilgrim)
|on Jun 22, 2012 at 16:25 UTC||Need Help??|
That's an important point, and subjective too.
I tried to use _ref. Then i tried using _hash and _list, but it didn't work for me : the code becomes less readable. I don't like:
Sam is not a hash.
Then i tried prefixes instead of suffixes, and i liked it better : i know that $h_ corresponds to %, and it doesn't get in the way so much. The beginning of a variable name feels (to me) like the right place to say its type.
I even thought of using capital letters :
I think i like these.
It doesn't make the "forgetting an arrow mistake" as obvious as suffixes, but it's better than nothing, and it doesn't get in the way as much.
Thank you for speaking about Data::Alias. I will give it a go. The % and @ symbols make for more readable code, I was wondering if it was possible to keep them. Every little help is good to take.
~ ~ ~
Another thing i have remarked, is that i don't always know what there is in a hash, or what keys i'm supposed to use with it. For example :
One way to deal with this is to make names more explicit. Or to add this information at the end of the hash, like this for example :
But it feels quite heavy to me.
What i like about it, though, is that it tells me which type of key is expected in the hash, and what the hash could contain, too. It does tell me a lot. I might use it in some occasions...
Maybe that a different style is better in different contexts... Spinach for thoughts.
It take lots of effort to make something easy to read, and people often don't notice it, but it does help them a lot.