$ cat post/why-we-can't-all-just-get-along-with-python.md
Why We Can't All Just Get Along with Python
October 31st, 2005. The leaves are turning in the northern hemisphere, and for those of us in tech land, it’s always kind of chilly. This month, I was knee-deep in a script-fest at work. You see, we were trying to standardize our monitoring tools across the organization—Python scripts versus Bash scripts versus Perl scripts. It’s like having a room full of developers who each picked a different flavor of ice cream and then arguing over which is best.
The Setup
Our team had been using Perl for quite some time now. We loved its flexibility, and with good reason—it’s perfect for text processing, and it has great community support. But recently, we started to see more Python being used in other parts of the company. Folks were praising its readability and ease of use, especially when dealing with APIs.
The Argument
One day, I was walking down the hallway and overheard a heated discussion between two senior engineers. One guy, let’s call him John, was passionately advocating for moving everything to Python because it’s “simpler” and more readable. His counterpart, Sarah, was just as fervent in her defense of Perl. “Perl is what we know!” she said, emphasizing every syllable. It’s like watching two kids fight over the last piece of chocolate.
John started rattling off some examples of Python code he’d seen recently—how it handled exceptions and file I/O seemed to him more intuitive than Perl’s syntax. But Sarah was quick with her counterpoints: “But Python is slower! And what about regular expressions? Perl does those so much better!”
I couldn’t help but chuckle a little, thinking back to when we started using these tools. It’s funny how our preferences can be so strongly influenced by personal experience.
The Script
To settle the debate, we decided to write a script together that would monitor our servers for disk usage and email alerts if anything was out of whack. I suggested Python, partly because it seemed more modern and easier to understand for new hires, but mostly just to see how it compared. John agreed, figuring it’d be fun to compare the two languages.
So here’s what we came up with:
Perl Script
#!/usr/bin/perl
use strict;
use warnings;
open my $fh, '<', '/proc/mounts' or die "Cannot open /proc/mounts: $!";
while (<$fh>) {
chomp;
my ($dev, $mntpt) = split /\s+/;
if (-d "$mntpt") {
opendir(my $dirh, $mntpt);
while (my $file = readdir($dirh)) {
next if $file =~ /^\.{1,2}$/;
print "Warning: $file is a directory\n" if -d "$mntpt/$file";
}
closedir $dirh;
}
}
Python Script
import os
with open('/proc/mounts') as fh:
for line in fh:
dev, mntpt = line.split(None, 2)[:2]
if os.path.isdir(mntpt):
for entry in os.listdir(mntpt):
path = os.path.join(mntpt, entry)
if not (entry.startswith('.') and len(entry) == 1):
print(f"Warning: {path} is a directory")
The Battle
Running both scripts side-by-side, we found that they produced the same results. But looking at the code, it was clear why Python was considered more readable:
- Python’s indentation-based syntax made for cleaner, more consistent code.
- The
withstatement in Python ensured files were properly closed without needing to explicitly close them.
However, Perl still had its advantages—specifically with complex regex operations and system calls. We both agreed that the choice of language shouldn’t be a fight but rather about what tool best suited the job.
The Outcome
In the end, we decided to keep our scripts in both languages for different use cases. For simple tasks like monitoring disk usage, Python was easier to understand and maintain. But for more complex operations involving regular expressions or low-level system calls, Perl still held its own.
It’s funny how these kinds of arguments can sometimes feel a bit silly—two grown adults fighting over syntax preferences. But in the end, it’s about finding what works best for the task at hand. And that’s something we all need to agree on as developers.
So here’s to Python and Perl, Bash and Ruby. May they live happily ever after—or at least coexist without too much conflict.