Readability of Perl vs C

Phred on 2007-08-30T02:18:42

Recently I've been doing some linux kernel programming. The main struct that I've been using is the socket buffer (skb). I used to be a fair C programmer when I was in school, but I've had a hard time getting back into it. With Perl the code just flows, with C I had to reorient my brain to think in terms of addresses and pointers. I think C is harder to read than Perl in general, but like other people have said, it is the coder not the language. Take this example though:

unsigned int tcplen = skb->len - (skb->nh.iph->ihl<<2) - diff;

This declares an unsigned integer tcplen and assigns it the difference between the length of the socket buffer and the length of the ip header bitshifted by two minus an integer diff (please correct me if I'm wrong :)

Not terribly bad, but one of the hard parts have been figuring out the details of the different skb components. Most of the documents on the web are dated by several years. Yes there is the sourcecode in the kernel itself, but it is definitely commented to a lesser degree than most Perl code I see, maybe because there is a higher barrier to entry than Perl code.

Regardless, I'm finding it very fun and challenging. Perl's sigils are one aspect of the language that has made it easy for me to understand it. The dereferencing (*) and address (&) operators in C have always been a bit more cryptic for me, but I'm getting back into the swing of it. Although sometimes I wish I had the skills to embed a Perl interpreter in the kernel :).