Learning Perl (and Perlcritic for TextMate)

Posted by matt
on Thursday, February 19

Now, just just leave straight away, but I’m learning perl. I know I’ve only just started waxing lyrical about python, but bear with me, I’ve not got any plans to dump anything else: I just need to learn perl for work. (If you read on in this post, you’ll find some ruby code, too!)

So, armed with some of the ideas from comments on my last post, I’ve tried to build make use of some of the most trendy web resources to help me on my way. Ideally, I’d like to pick up on best practices as I go along.

information overload

So far though, I’m not having a huge amount of luck. I’ve worked through learning perl, and I’ve finished reading it feeling like I don’t know anything like the whole story. To be perfectly honest, I’m quite surprised at the complexity of what seems like a small language!

I’ve got a huge pile of books to help though, so I’m going to start digging through programming perl, and setting myself programming goals. My aim is to work out how to write simple modules and unit tests by the end of next week. I’d also like to find some rake/paver equivalent, and work out how to effectively use Devel::REPL (which stackoverflow helped me find.) Soon I’ll have my automation / test safety net at the ready, so things can proceed a little faster.

Whilst casting around, I found Perl::Critic, a module (and front-end) for checking your code’s adherence to best practices (incidentally, there’s a great book called perl best practices – another one on the pile!).

I decided to write a TextMate command for the perl bundle to run code through perlcritic, since there isn’t one. After a little help from the bundle developers mailing list, I came up with the following:

To run this, you will need a new copy of the TextMate Support directory. I’d suggest using GetBundles. I’ve sent a patch to the perl bundle to the ML, but in the mean time, if you paste the above code into a bundle command, set the scope to source.perl, and trigger to ⇧⌘C, you should get it working fine.

Update: I’ve just started reading programming perl, and I wish I’d started with it! I’m already feeling like I’m learning more useful stuff than was contained in learning perl. I guess I’m not the target audience of that, but I wish I’d known last week!

Best Practices and Patterns

Posted by matt
on Sunday, February 15

Listen to this post

One of the things I’ve noticed during the course of my studying for my PhD is that there’s is a gulf between knowing how to do something, and knowing how to do in a way that’s acceptable to others. I think that this gulf is one of best practices.

If that’s not clear, then let me illustrate it with an example. I believe that almost anyone can do research which is suitable for publication (honestly, anyone!), but the actual process of publication is far more difficult (I’m speaking as someone who without a huge amount of experience in this area).

To have work published, you must follow a complex sequence of both explicit and implicit rules. These rules represent the best practices of scientific writing, and without knowing how to follow them, even if you don’t know what they are, you will have a hard time getting things published.

This process boils down to ‘learning how to play the game’ or pick up the idioms, and seems to generalise to almost every other problem domain – at least those that I’ve come across.

Does my description above sound familiar to you? I thought so. Maybe you’ve tried to commit to a well established open-source project; you probably had to study the coding style, look at how tests were implemented, maybe even learn how they use source code management.

In my experience, a normal part of any learning process, perhaps even more important that the initial, and traditional learning stage, is finding out how things actually get done. I’m hoping that by building finding out about this kind of issue into my learning processes, I’ll be able to get to a useful state, one where my output is usable by others, quicker, and perhaps not have to unlearn bad habits which I picked up when I started out.

How do you find out about best practices? How do you build them into your learning processes? Let me know in the comments below.