Tag Archives: perl

Sounds Like a Job for Perl

In which I write a continuous build system for bagpipe music using Perl and a Makefile.

The problem: the band has sheet music that everyone is supposed to memorize, the membership is geographically dispersed and not everyone can make it to every practice, and during practices and workshops and after competitions the music can get edited to reflect feedback and (one hopes) improve the performance. How do we distribute the music to everyone?

Continue reading

Programming for the Ages

So this feels like the most Silicon Valley thing I’ve said in a few years, but the thing I’m working on right now is basically the same parts and programming language I was working on as a hobby back in 1997. Yes, the machine is in someone else’s data center, yes, the services it’s interacting with are running in still other data centers; even so, I am writing Perl CGI scripts and cron jobs to respond to automated messages and run intermittent build and release processes. What a blast from the past.

PDF::API2 and Landscape

I’m currently working on a way to generate a custom PDF of a Bugzilla record (which, in turn, contains a bunch of custom fields). One of the requirements of the spec is that the PDF is targeted at US letter size paper in landscape orientation. I’m looking at using PDF::API2 and PDF::Table but one of the problems I had, just like manu, is that when you call $page->rotate(90) it sure-enough rotates the page at render time, but it’s really as if you printed on a portrait-oriented page and then turned the page sideways. This is not what one expects, since this is not, at the end of the day, something that one has much call to do.

Here’s how to achieve the actually desired effect: set the mediabox manually to the appropriate settings for a landscape orientation.

$page = $pdfdoc->page();
$page->mediabox(0, 0, 11*72, 8.5*72);

In my code I’ve defined a function that returns that list so that the code can be a little more descriptive:

sub LETTER_LANDSCAPE {
    return (0, 0, 11*72, 8.5*72);
}

...
$page = $pdfdoc->page();
$page->mediabox(LETTER_LANDSCAPE());

There’s probably a prettier way to do it, but at least this works. Gotta ship code, man.

Why You Gotta Hate?

For the past three weeks I’ve been working on a Bugzilla system. Specifically, working on fixing small bugs in the UI code of a customized Bugzilla installation. This system has been highly customized, with lots of new Javascript as well as a lot of server-side extensions to customize the process of bug entry and workflow. Bugzilla, in case you didn’t know, is written mostly in Perl. There’s some Javascript and the pages are all rendered with Template Toolkit, so basically, it’s Perl. The last time I worked with Perl, I wrote a couple of scripts to automate some image conversion on Windows machines. At that time, I didn’t need an IDE; Notepad was plenty for the needs of a program that used a single file. Bugzilla is huge. It has hundreds of source files and none of them are self-contained. Every file refers to at least one other file and most refer to several.

Bugzilla is written in Perl but it’s object-oriented Perl. After one day of using BBEdit (a swell text editor that I’ve used on and off for decades) to try to navigate around, I found myself really wishing for an IDE. There exist projects that claim to be Perl IDEs. There’s a Perl plugin for Eclipse (that is slow and just functional enough to be tantalizing, but all it really does is syntax coloring, and not even very well). There’s Padre, which looks swell but doesn’t do even as well as BBEdit for editing and the other stuff doesn’t work. Eventually I tried IDEA, since I have a license for it. It does syntax coloring and multi-file search and all that stuff that BBEdit does, while adding the knowledge that everything under a given folder is part of the project and not to worry about stuff outside the folder. It doesn’t really have Perl support so I still can’t do the really powerful stuff an IDE really lets you do. I still wish for a tool that lets me put the caret in a symbol and then, with a keystroke, go to the declaration of that symbol, wherever that may be within the project.

Other tools that my group support are written in Java, Ruby, and Groovy. It’s enough to make me cry, just a little bit. I’ve been going through Ruby and Groovy tutorials and, okay, I get the amazing power of Rails/Grails. That right there is 100% awesome. If you’ve gotta spin up a prototype web service in a hurry, man, Ruby on Rails is hard to beat. Looking at the language features, though, and the language comparisons (try Googling for “compare ruby java” or “groovy language features”) I start feeling tired. Why do so many people make such a big deal about closures? Are there really that many programmers developing self-modifying systems? Seriously, Lisp is an amazing language that is super powerful and awesome, but most of its awesomeness would go to waste if you’re writing a blog or an online bill paying site.

I’m starting to wonder why so many people seem to be allergic to languages where you can know, just by looking at the declaration of a method, what the method expects the parameters to be. Perl doesn’t even declare parameters, Ruby and Groovy do but the type is optional at best and usually absent. When my little chunk of code gets an object and I want to do something with it, I start wondering, “What kind of thing is this object? What can it do? What kinds of state does it have? Is it even reasonable for me to try to do anything with it?” Some might argue that I (and my code) shouldn’t wonder these things. It should be the job of the caller who’s providing the object to be sure that the object is appropriate for my code. But that’s just sweeping the problem under the rug: how in the world can the caller know, since my method doesn’t advertise parameters? It’s the same question, really.

The big advantage that I keep seeing touted on tutorial websites is that these scripting languages require less typing than stricter languages like Java or C++. You know what? I’ve got a solution for that: learn to type. Holy cow, it’s not like memory is that expensive, that the difference between having braces and no braces in the source code is gonna kill you. Source code should be readable by humans. Okay, open question to all you Perl/Python/Ruby/Groovy/whatever-the-fuck-scripty-language guys out there: why do you hate knowing what type of thing a variable is? Why do you hate tools that tell the programmer what’s going on? Why do you think that the best source code editor is ed? Jeez, guys, programming is fun, why do you have to make it so tedious?