Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

xsawyerx (8978)

  (email not shown publicly)

Journal of xsawyerx (8978)

Wednesday January 28, 2009
04:26 AM

Some good personal practices

[ #38355 ]
One website I really like is Andy Lester's, 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
  • use English '-no_match_vars' - there's a nice comment on programming that I always found funny, but I prefer Larry Wall's quote on TIMTOWTDI, that you should "... try to pick the most readable one"
  • 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!
  • Template Toolkit for web, Text::Template for everything else
  • List::MoreUtils - "any" and "none" are two very helpful functions
  • DBIx::Class and DBIx::Class::Schema::Loader - never use DBI directly again - to those who like relational mapping.. some don't
  • Starting to use Net::OpenSSH for ssh and scp instead of Net::SSH::Perl and Net::SFTP which are difficult to install
  • 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.
The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.