Wednesday, May 14, 2008

Succinct code

So the job...

Existing build system written in very clean and clear Perl. One of the advantages of Perl is that code is usually all the doco one needs if it's written by a reasonably competent Perl programmer (i.e. not a C or Java monkey in Perl clothing). Interestingly, a reasonably competent Perl programmer usually also adds useful/relevant comments. Java programmers OTOH love to put in comments like "the following adds 1 and 1 to make 2", followed by '$result = 1 + 1;'. Life is too short for this type of idiocy. I recently looked at a 600-line Perl script which did less than ten lines of xsh code. I also remember a few years ago a Java columnist demonstrating that now that Java had a regular expression library he could write his particular script in only 100 lines! The equivalent in Perl is a one-liner. 100 lines of code rots the brain if there's only one relevant line. Which is the relevant one? How much energy do I have to expend to process the other 99 lines to work out they are not the nub of the code? Of course, Java and many other languages aren't as succinct so one's thoughts are never as clear or focussed, they are always diffused over the other 99 lines.

No comments: