Thoughts on Perl and Emacs, technology and writing

Surely Perl Is Not My Perfect Compromise

Yes, Emacs is my OS, but I still need to run external programs not written in emacs-lisp from time to time. For example, emacs doesn’t have a method for processing a section of a file – without help from an external program, you need to load the whole thing into a buffer.

Why learn a new programming language?

And no, because the pragmatic programmers told me to learn a new one every year is not a good reason. If it is something you need for work, then the choices is normally straightforward – learn whatever they tell you to learn at your firm.

Languages Used in Industry

If you don’t have a job and want to get one, choose C# if you like Microsoft, Java if you don’t or perhaps PHP if you want to do web programming. C++, Python or Perl might be reasonable choices depending on which industry you want to go into. And no, Python did not "kill" Perl nor did Ruby "kill" Python.

Language Complements

If you already know a systems language such as Java, C# or C++ it is worth learning either Python or Perl. The reverse is a weaker proposition but still true in my opinion. However, if you already know both a systems language and a scripting language, any time invested in learning a new language could be used to improve your knowledge of one of your existing languages – maybe learn a framework such as ACE, Twisted or POE.

Studying For Fun

It may be worth learning a new language if you are just learning for fun and your existing languages don’t cover a particular problem area that you are interested in. For example, if you want to write GUIs and only know C++ and Perl maybe you should learn Python so you can use wxPython (just kidding!).

The problem then is that you can’t do a thorough evaluation of a new language in a small amount time. Perhaps the best you can do is to list features that are important to you and exclude languages on that basis.

So for me, I don’t like to write C++ in my limited spare time and my second language, Perl has a few minor flaws such as threading1. I’m looking for a replacement for pottering about with. My big ticket requirements are:

Nothing to do with .NET

Portable to at least Linux and Windows

I would prefer run-time size to be small for simple program

It must have a REPL I can run from Emacs

It needs to have fairly complete libraries (which implies)

It must have a reasonable size user community

Pre-emptive threading would be nice

The JVM Languages

JVM based languages neatly solve the libraries issue and you get threading and portability too. The two languages I would consider here are Clojure and Scala. I’m more interested in the former but I’m a bit concerned about run-time size. From what people tell me, three or four Java clients is all a decent PC can take before it falls over.

D, Haskell, Ocaml

I suspect all of these make relatively small runtimes. Haskell immediately excludes itself as any language where I can’t put a Printf where I want sucksis not the language for me.

Scheme / Common Lisp

There are simply too many scheme implementations which must affect the size of the user community so I’m ruling scheme out. And if I’m going to run a Common Lisp VM, why not use Clojure instead and get the Java Libraries for free?

Lua

Lua covers most of the points. I just need to check if it has a REPL.

So following that set of (weak) justifications, my shortlist consists of Clojure, Ocaml, Lua and Perl of course. Next I’m going to do a very basic check of runtime size.

1. Since discovering POE, I haven’t needed threads so perhaps I should admit that whenever raw speed is unimportant (and that is usually the case) Perl might be my perfect language.

However, as a user of a couple of well packaged Python stuff on Windows (despite my Ruby love), I think Python should be on your shortlist. It has that Google-approved quality (sorry hype is seeping in), Windows integration that feels better than Ruby or Perl, and that first BitTorrent client in Python on Windows was from a performance perspective, very user-satisfying. Then again, I’m pretty satisfied with some Tcl/Tk apps like gitk even on Windows. I cannot recall a Perl or Ruby GUI app that I like.

What I hate is installing a runtime. Ruby’s installer craps 20MB+, many are small text files. Lua feels the same. I suppose Python is the same as well (OK, you put .py there, now you want to put .pyc and .pyo!?) Let’s not forget the .NET stuff and JVM stuff. Install times just drag.

I want to like Clojure, but JVM startup time kinda kills it for command line use.

Actually, most of my spare time scripts are Windows only, so that means unsavory forays into CMD and AutoHotKey. (Very anti-composable, these languages are) Though they make my computer usage more fun, and that’s what counts.

[…] SparksSpace added an interesting post on A Curious Programmer: JaredHere’s a small excerptIf you don’t have a job and want to get one, choose C# if you like Microsoft, Java if you don’t or perhaps PHP if you want to do web… […]

I’m not clear on if you ruled out/already know Python. It was the last
one I learnt mainly because I wanted to do some prototyping and it is
a lot cleaner than Perl. I suspect I shall make more effort to write
new scripts in Python rather than the usual Perl.

I’m currently wondering if it’s worth going to the effort to learn C#
to play with the Banshee code. Of the others you mentioned I have
heard good things about Lua as being particularly easy to embed in
your own code to add script-ability. A few jobs ago the performance
team used it to add programmable hooks to their performance collection
scripts.

@anon – Hi, I know that Clojure is not a Common Lisp. What I was trying to say was if I was going to run a heavyweight VM like Common Lisp, why not use Clojure + JVM instead (and get the java libraries in exchange for some common-ness). Does that make sense?

@Piyo – Yes, I like to dabble too :) My Perl is pretty good, but I am thinking about looking for a replacement – hence this post. Having said that, as I mentioned in my footnote, if I don’t need speed it does pretty much everything I need and it does it cleanly and well with very little fuss.

Yes, I know there are lots of good things about Python but really Perl on Cygwin works well enough for me on the few occasions when I need to venture into the Windows desert. And I can’t think of many areas that I am interested in where Python has something that Perl does not. It would feel like gratuitously learning the same language again only with less convenient syntax.

Hmmm… now I read that again, maybe Python would solve at least my portability concerns. But then again, maybe there is another language that does so even better.

And about the rant, well, I see a lot of stuff written about emacs-lisp too. And sure, neither Perl nor emacs-lisp are perfect languages. But they both have the same redeeming feature – libraries. The problems that I solve in either language has been 90%+ solved by the libraries available. And how can any language, no matter how good, compete with that? E.g. for database mode, what I want is a text editor (check) with emacs keybindings (check) and SQL syntax highlightling (check) that can send SQL snippets to the database? 5 lines of my own code later, I really appreciate those libraries.

And I completely agree with you about the large runtimes. Maybe Neko is where it is at.

Of course, It’s Your Free Time (TM). ;-)

Heh, now where do I recognise that meme from… :)

@Michael – I’m not sure what you mean by new people. They are all over 20, I guess that isn’t *that* new. But they are using relatively powerful PCs.

I know your comment is in response to a [different] flippant remark, but isn’t it the case that if you are running a heavy-weight app, that you tend to give it a lot of memory (with a command-line switch) that it immediately takes and never returns to the OS?

@Alex – I’m not quite on first name terms with Python but I did use it for a few months back in the 1.5 days. I got the impression that aside from a few niches such as SciPy it covers the same areas as Perl with no significant advantages on either side.

I know Python proponents talk a lot about code cleanliness and readability. This is of course subjective and I find at least my own Perl more readable than any Python I have come across. I respect the right of Pythonistas to disagree with me on this one ;)

@Alexandr Ciornii
> Strawberry Perl, ASPerl
Thanks for your concern. I’ll just let Cygwin and git on msys install their respective Perls and use those indirectly.

@Jared
> I really appreciate those libraries
I understand your argument, because I apply the same ideas to my selection for my main OS and my unsavory forays. Anyways I’m satisfied with your response to my response, so keep plugging away (e.g. your recent post about A Simple Perl Server).

@Alexandr – if I don’t care about the GPL are there advantages of Strawberry Perl over Cygwin Perl?

@Piyo – I don’t suppose you can elaborate re: the advantages you find with Windows. I mean, I can think of a few things myself but always found that the standard availability of stuff like shell/perl/make + package management makes Linux the better development environment for me. Well, unless I’m doing C#.

Well the last thing I did in Python was adapt an existing psychometric
testing script that ran on Windows to use some rather funky display
hardware that only had Mathmatica, VB and C# support. Luckily I
discovered the excellent ctypes package and was able to interface the
script directly with the hardware control DLL. The fact I was stuck
with Python anyway I shudder to think how I’d would have dealt with
the problem in Perl, especially when operating in the foreign waters
of Windows!

I too take care to write clean code in perl (which usually ends up
looking like well structured C). However I still occasionally get
bitten by some of perl’s more esoteric behaviour. The thing I liked so
much about Python is it’s behaviour was so predictable and consistent.
That’s a big plus for a language you don’t work with every day.

Yes, consistency is a good thing in programming languages. I use Perl frequently enough that I’m not in much danger of forgetting the quirks. Sometimes that bites me in that I’ve only just started to adopt the lexically scoped three argument open (from 5.8 I think) instead of using global globby filehandles. And I haven’t even started using Moose instead of blessing my references directly.

And if I was a Windows guy I would probably consider Python although I really should take a look at Strawberry Perl one of these days.

Don’t you find it interesting that even when *trying* to talk oneself out of using Perl, we still gravitate back towards it? If hacking isn’t fun, there’s little distinction between flipping bits and burgers.

I’m not really trying to talk myself out of using Perl – I really like it. I just figure that one day there will be a project I want to do which could be done better in something other than Perl. If I haven’t learnt that something beforehand then I’ll just reach for my standard big hammer.

Alex Bennee: I had similar task (using dll). I just run a tool to convert .h to Perl module.

Jared: Strawberry Perl has gcc integrated into distribution, so it is easier to install CPAN modules that require compiling C. ActiveState has similar feature now, you can install gcc with `ppm install gcc`.
Compared to Cygwin, it not an advantage, of course. For me it a question of habit – I don’t use Cygwin. Small advantage in both Strawberry and ActiveState is possibility of using ppm when external C libraries are required – it can be easier than installing library in Cygwin.

P.S. Another interesting Perl module is Perl::Critic, it helps to write more modern and more maintainable code.