That's an important point, and subjective too.
I like my code to look as much as possible like english : i like when i just read it and it says what it does. Without having to remember that some letters are just here to give technical information, so "you have to try to imagine that they are not there."
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.$age_of_hash->{Sam};
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.
feels better.$h_age_of->{Sam}
I think i like these.$H_age_of->{Sam} $L_items->[2]
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 :my %data_from; # File? Measurement? Experiment? etc. my %height_of; # Furniture? Object? Person? etc. my %results_list_for; # the keys could be almost anything
But it feels quite heavy to me.$data_from_measurement{measurement->label()} $height_of_furniture{$old_furniture} $results_list_for_file{$file_path}
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.
In reply to Re: Perl Best Practices for naming variables
by mascip
in thread Perl Best Practices for naming variables
by creamygoodness
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |