Reading Source Code

redspike on 2009-08-29T23:56:12

Last night and tonight I started to read the code in several Perl modules and I realise why it is a good thing. It seems daunting sometimes as I have felt that I need to know so much more before it makes any sense. References, anonymous arrays/hashes and autovivification has started to make sense and by reading the source code I can see how this all fits in even though I am not accomplished at using them yet, the whole subject is not such a closed book.

I have read numerous books, in fact I have more Perl books than on any other single subject onmy shelves, but they do not always help. There is an assumed knowledge which is often expected and not always explained. It was reading Eric Steven Raymond's article on hacker culture where he said that reading and writing code was more useful than going on courses or reading books, that prompted me to read the modules in the first place. The most gratifying thing was that I did understand most of it and because I was reading modules that I have a little knowledge of and what they do I could make the connection between the code and the end result.

I have found Perl very confusing at times because there are so many ways of doing things (I know this is also one of its strengths) and so faced with such an array of different ways, I have often opted to not do them just because there seemed to be no road map. Now that I am starting to 'get' a few things I see the deep pleasure of understanding how it all works and how, by that understanding I can use Perl to solve programming problems. My main gripe is that it took a lot of effort to get to that point. Whether that is because I have had to find a particular way of learning Perl for me, or whether that is a general problem in the methods of teaching Perl, I don't know but I am going to explore that as I go through the process and hopefully be able to lay down some pointers for others who may have a similar problem.

So if there is anyone out there struggling with getting started, have a go at reading some source code, it puts a lot of the programming techniques into perspective and gives you a starting point to research the things you are reading. Being code that is in production and not just in a book which can only give examples because of the limited space and worth in that format, means that it is easier to see the point of the structure that you are presented with. Relevance to the real world is very important in understanding.