Actions from Andrew ProperMovable Type Pro 4.382012-08-01T04:39:25Zhttp://blogs.perl.org/mt/mt-cp.fcgi?__mode=feed&_type=actions&blog_id=0&id=1962Commented on Almost a year of Perl news... in Gábor Szabó - גאבור סבוtag:blogs.perl.org,2012:/users/gabor_szabo//272.3632#1827062012-08-01T01:39:25ZAndrew Proper
Gabor, I'm a subscriber and I greatly enjoy reading the Perl news every week. Thanks for your effort! It's helpful and informative.]]>
Posted Extensible Maintainable Subroutines and Methods to Custom Perltag:blogs.perl.org,2012:/users/custom_perl//1444.36452012-08-01T01:09:41Z2012-08-01T01:09:51Z I've been thinking about the way I write Perl subroutines and methods as compared to some other Perl programmers, and I've decided to write a post about it. To make my subroutines and methods more reusable, extensible, and maintainable,...Andrew Properhttp://blogs.perl.org/mt/mt-cp.fcgi?__mode=view&blog_id=1444&id=1962
I've been thinking about the way I write Perl subroutines and methods as compared to some other Perl programmers, and I've decided to write a post about it.

To make my subroutines and methods more reusable, extensible, and maintainable, I make them receive a hash reference as their only argument and return a hash reference. This has multiple benefits.

First, the parameters going into the subroutine are named when passed in, and these names are used to identify them inside the subroutine. This means that new parameters can be added with keys in the hash, a very minimal change. The same is true of the return hash. Using keys in a hash is far simpler to maintain than using positions in a list. I've spent enough time wrestling with indexed parameters in subroutines that I never use lists of parameters in code that I expect to use more that once (which is basically all of it).

Second, a hash reference is passed in instead of a hash because the reference can be tested using the ref function to ensure that is is actually a HASH ref. Assigning @_ to a hash is not as robust. The same is true of the returned hash reference.

Here is a brief example of a subroutine that receives and returns references to hashes of named parameters:

And that's the basics of it. What do you think? Comments are very welcome.

]]>
Commented on Perl Coding for the Win in Custom Perltag:blogs.perl.org,2012:/users/custom_perl//1444.3637#1823132012-07-31T11:27:50ZAndrew Proper
Thanks for the welcomes!]]>
Posted Perl Coding for the Win to Custom Perltag:blogs.perl.org,2012:/users/custom_perl//1444.36372012-07-31T02:05:41Z2012-07-31T02:10:25ZI’ve been writing programs in Perl since about 1999. Wow, that’s a long time now. That was way back when I was studying Computer Science and working for the IT department of the University I went to. I still write...Andrew Properhttp://blogs.perl.org/mt/mt-cp.fcgi?__mode=view&blog_id=1444&id=1962
I’ve been writing programs in Perl since about 1999. Wow, that’s a long time now. That was way back when I was studying Computer Science and working for the IT department of the University I went to. I still write Perl programs these days, at my current job, where we call it Application Development.

Since I like Perl development a lot, and I like learning about Perl, I figure I might like writing about Perl too. So that’s what I’m thinking of doing in this blog. I hope some of you find it interesting and useful. After all these years of experience, I might have something to say that you might find useful and/or interesting, especially if you are starting out with programming and/or Perl coding.