Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^5: Improve readability of Perl code. Naming reference variables.

by stevieb (Canon)
on Jan 21, 2017 at 14:13 UTC ( [id://1180083]=note: print w/replies, xml ) Need Help??


in reply to Re^4: Improve readability of Perl code. Naming reference variables.
in thread Improve readability of Perl code. Naming reference variables.

Now you've circled back around to scope size again. If your sub is around one screenful of code, it's easy to know what each var is and does, because you can at a glance see it in use without paging or having to search an entire file.

Then, you have your documentation (you did write documentation, right? ;)

Often when I'm writing new modules or updating older ones, I have the current documentation open in either a browser or another terminal window. Your documentation will provide you with the function/method declaration, and will clearly describe what each parameter is. I'm not advocating using comments here, I'm just saying in rare cases where it may be ambiguous to the reader, throw in a comment. fwiw, I don't recall over the last year ever having to specify what a variable is via comment in any of my code.

In your example, with those names, I immediately and instinctively knew which type each param was. If I was to update that sub, the worst thing that would happen would be an error spit out because I mistakenly used the variable as a different type, and since I test code extremely often, there wouldn't be much I'd have to go back and change to correct my oversight.

  • Comment on Re^5: Improve readability of Perl code. Naming reference variables.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1180083]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2024-04-19 02:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found