April 26, 2005 at 11:01PM Hacking Greymatter pt. 1: First attempt.
I spent a good five hours last night trying to do some light refactoring on Greymatter. I thought it would be fun to exercise my Perl-fu on it.
So I sat down, threw on some Boards of Canada, and hacked. First I scanned the code and looked for whatever low-hanging fruit I could. The first thing I thought to do was to take each function one-by-one and make their variables local using the my operator, and the same for file handles with the local. This turned out to be more soul-destroying than I though.
The thing is, the functions were just too big! So I changed my tack and thought that I’d try refactoring all the file loading and saving code into their own functions. I mean, from scanning the datafiles, it all looks similar enough. Only it’s not.
So, why not try factoring out the date processing code? With this I’d more success: I actually managed to create a bunch of functions that encapsulated all that (needlessly extensive) date-processing logic. Mostly.
But even then, it just wasn’t enough: I decided the only way was to design a new and better way to store the program’s data, write a script to extract the data and convert it in the new format. That I’m going to do this weekend.
When I’ve that done, I’m going to extract all the backend templates, and using only the manual, I’ll write something that is, on the surface, functionally equivalent to the current version of GM.
I’ve a layout for the new backing store worked out. There’ll be one file per entry, and one file per comment. In both, the file format will be a header containing name/value pairs, followed by a newline seperating the header and body, and then the body. Karma will be stored in its own file.
Equally, templates will be stored in their own files for both the blog itself and the administrative console. The blog metadata will be stored in its own file, as will the counters and so on.
Whether these will be stored in their own file format, or be Perl code, I haven’t yet decided. The templates will be just plain HTML files, and I’m thinking of simplifying the templating language, mainly to make the tokens shorter, and to implement file inclusion and simple iteration. I’ll be converting over my old PHP FastTemplate clone (which doesn’t suck as much as the original Perl one), which does most of that as it is.
Oh, and it’ll use CGI.pm, goddamnit!
Let’s see how it goes.
No comments.