Clojure and Perl: Noticing First Differences

This post is not intended to be a contest of one language versus another. We are using Perl for a water project for a number of pragmatic reasons, like folks working on the water project who do not know Clojure and Perl’s DBI support to name two.

Instead, this post is about something I’ve noticed, having used Clojure on a few small projects, and now returning, like Kellog’s Corn Flakes, to Perl again for the first time (since 2000, and then again in 2003).

I am re-writing three major Informix 4GL programs in Perl. They rely heavily on Perl’s DBI, and hence need to store a lot of intermediate data. So, there are quite a few module and subroutine scope variables. For me, the striking difference between Perl (and perhaps languages like it, including 4GL, VB, and so on) and Clojure is my Clojure programs don’t seem to need variables, other than global vars and data bound in let statements.

I believe my appreciation for Clojure’s immutable data is as full as it can be for someone who has worked with the language for a couple of years, so I appreciate that you cannot initialize a variable and modify it. The design of my Clojure programs always was different, despite the fact I could have bound a lot of let variables wherever I needed them, but I just never needed to do that.

The data seemed to come and go. My Clojure programs read in data; manipulate that data, make network I/O calls using that data; and then write some of that input data and new data out to disk.

When I first started learning Clojure, the luminaries said my views of designing would change, and I believe they have.


Cleaning up Perl Programs

I don’t know why, but my Perl programs have always seemed to lend themselves to lengthiness over brevity. That is not the fault of Perl itself. Part of my problem is [re-]learning a new language again for the first time, and keeping all the code in one place for easier debugging, and part of it is I am only just seeing what could be possible in the ability to use both array and hash references.

For example, like variables could be created in a subroutine and returned as part of a  hash ref or array ref. Variables can be declared as needed, something I do not remember as part of Perl, when I used it thirteen and ten years ago, respectively.

As I write several new programs for new rate structure and quarterly water billing, the code will get cleaner.


Programming Languages Used and Using

These are the computer programming languages I have used over the past few years.

1985 – 1987

PL/I Subset G

1987 – 1990

C, Bliss, Assember (DEC VAX)

1990 – 2000

C, C++

2000 – 2002

VBScript/VBA

2002-2003

Java, C, C++, Perl

2004 – current

Informix 4GL, C, VB, Perl, Python, JavaScript, Clojure