One website I really like is Andy Lester's Perl101.org, which lists a lot of good practices in Perl programming that was accumulated over the years by veteran programmers and presented to other novice and beginner programmers alike.
I recently decided to write down some of the practices I use personally, in order to remember myself things I've learned over the years. I would like to share them in the hope that it might be helpful to someone else and that others might comment and enrich me as well, since as all of us, I have much more to learn.
Moose it! Not a strict rule since there might be times you wouldn't want to, but I generally use Moose
use Carp - use croak() and carp() when inside modules
Write applications as modules - it allows testing and easy distribution, App::Ack is a good example
When using Moose, use MooseX::Getopt to provide your module with ability to read configuration files (YAML/Generic/INI/etc.) and have command line options at the same time
File::Spec can be used to get folders and files in an OS compatible way - always use it!
Reading and writing files with File::Slurp - the way file reading/writing ought to be in a very high level language
WWW::Mechanize - they say "jesus saves".. well, so does WWW::Mechanize! (and a hell of a lot more than jesus!)
Input from users with IO::Prompt - sometimes misbehaving, but very comfortable
A few extra comments:
Perl::Critic to the max! That's how I reached many of the things I noted above, and it helps me improve my coding all the time
Test before coding, seriously. Many a times, it helps define what you're doing and makes sure you're doing it right. I started using testing suites as a general tool instead of just for modules and applications.
Document document document. Documenting makes sure that you're still up in par with what you're trying to achieve and help whoever works with you understand what you're doing. Also, it helps think about things and perhaps reach better solutions.
Programming is 80% thinking, 20% writing. Don't just write. Think what you want to do, design an API, etc., then write tests for what it's suppose to do and how to use it. The tests define the API for you. Write it, then document what it's doing in better detail.
Some good personal practices 0 Comments More | Login | Reply /