C -> Perl

jplindstrom on 2003-01-15T01:46:47

This afternoon, in order to add a little functionality, I re-implemented a small server program (basically just extracting and serving log files), written in C.

Before: 750 lines, 25K After: 150 lines, 6K

Had I not been forced to follow a home grown protocol it would have been smaller and gone quicker (HTTP::Daemon and all).

Why do people keep writing their own protocols when there are existing protocols with existing implementations that work just as fine? This protocol was stateful when it didn't need to be, so HTTP would have worked nicely.

One thing I noticed and appreciated is that Perl's old inheritance from C with identical networking commands got the IPC code real easy to port from C.

A 5:1 code size ratio seems a bit large even for C vs Perl, and admittedly it wasn't the tightest C code I've seen.

In another C-program I re-wrote in Perl (the original never got stable, so we got tired of cleaning up the mess it left behind) the lines-of-code ratio was something like 3:1, with a bit more functionality and a lot more stability in the Perl version. That, and unit tests.