Stockholm Syndrome

Or, the donkey between the haystacks

November 4, 2021
programming php nanogenmo

I’m starting a new temporary project, NaNoGenMo (again). Here I attempt to write a program that generates a 50k word novel during the month of November, because NaNoWriMo (where you just write the novel) would be too easy. As always with any software project that doesn’t have any constraints, there is a choice of language in which to implement it. Sensible languages for such a project would be Lisp or Scheme, as it is AI related, and these languages are well-suited to it. (Note: a lot of so-called AI is nowadays done in Python; but that is mainly machine learning, which isn’t really AI in the sense that I understand it. Also, I haven’t really done any serious Python development, so maybe not this time).

However, I have decided to use PHP.

This is a somewhat surprising choice (even surprising to myself), as I don’t like PHP. It’s a hacky language, which is horrendous. But recently I have done some work in it for the sailing club, where our results are calculated with it, and I got used to it. For all its faults, it has a good library, and is fairly flexible. You can even write programs in a kind of functional style. And it’s ubiquitous on the web, so if I ever want to run my system (or parts of it) on the web, I should have no problems doing so.

You can run it pretty easily (just with php YOUR-FILE), so you don’t need to worry about build files or class paths or other complicated stuff. And it’s portable.

In a way it’s a very simple and straightforward language, so I can pretty much focus on what I want to do, and don’t need to worry about the how. I’ll see how it goes, but so far I’m quite happy with it. Especially since I realised how to call any function based on its name, which means I re-invented some kind of object system… if an object (a plain array) has a key “fn_print”, then that is used to print itself. Very easy and nifty. Similarly I can compose function names from some other values, and then call a function. I can even check if it exists, and fall back to a default if not.

Yes, with other languages you get that kind of thing for free, but sometimes it is easiest to take what’s in front of you. I have railed against PHP in the past, and it’s not a good language, but it’s there, it’s everywhere, and it’s easy to use. So let’s see how I get on with a larger project!