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 ]

Phred (5358)


Fred is a Perl and PostgreSQL geek. He has made some very small contributions to a few cpan modules and mod_perl.

Journal of Phred (5358)

Wednesday August 29, 2007
09:18 PM

Readability of Perl vs C

[ #34275 ]

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 :).

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.