This blog is also available on Gemini (What's Gemini?)

Don't Get Bent Out of Shape About Being Cross Platform


We had an interesting exercise at the recent Madison Perl Mongers meeting[1], where we took an ugly Windows shell script and turned it into a Perl script. The resulting Perl was noticeably longer than the original script, but also had functionality broken up between subroutines, and was far easier to understand.

One of the sub-problems was to get the current free space on the disk. After some searching with Google and Perl Monks, I found Win32::DriveInfo[2]. Problem is, it isn't cross-platform.

I didn't want to bring up a counterargument right then and have to explain it out, because we could have been debating it the rest of the night. But here's my position: I don't care if it's cross-platform or not. But I don't care in a carefully considered way.

This particular script was for an automated daily sysadmin task on a couple of Windows servers. There is no guarantee that it will ever need to run on anything else. So what I would do in the real-world is make a short search for a cross-platform alternative. If nothing came up within a few minutes, I would shrug my shoulders and wrap all Win32::DriveInfo access into its own subroutine and move on.

As it happened, some people already knew about a cross platform solution (I believe it was Filesys::DfPortable[3]), which is fine. But if I hadn't found that (and it's really not a good, easily searchable name for a diskspace module), I wouldn't worry about it.

It might be that I never have to port it to another system. In that case, my search would be a big waste of time. What I need to do is write it in such a way that it's easy to pull out the old behavior and substitute it. This way, if I ever do need to port it, the job will be easy.

Furthermore, you'll almost certainly make hidden assumptions that aren't cross platform, anyway. The history of Java ought to be a lesson here.

One of the goals for this committee hacking session was to make the script cross platform, which was fine. I just don't see a reason to get overly concerned about it, provided you otherwise write code in a modular way.