Nice week this week. I started out with an incredibly large and neat refactoring; it looked like it was gaining in size and complexity until a colleague reminded me to slow down, atomic commits and assign to each commit a specific purpose. It meant I stopped, took a few minutes out and worked out what the order and purpose of each commit was.
When I did that, it became incredibly clear what my order of operations should be, and it also became clear just how much extra value small commits have. I was committing bug fixes that were immediately available, instead of making coworkers wait for a code dump. It’s always good to be reminded of self-discipline.
I spent a bunch of night time working through the const keyword and its relationship to pointers. Here were the scenarios I wanted to understand:
const foo* bar = bam;
foo* const bar = bam;
const foo* const bar = bam;
Once I could conceptualise the idea that sometimes you want to track a constant address and sometimes you want to track constant data, and this is separate from using a variable to track an address and data because a variable actually encapsulates the memory footprint of the object as a whole, it all fell into place.
Beyond that, then, I watched a lot of Avatar this week. My girlfriend and I have really been into it; it’s such a cool little show. I’m really impressed by how consistent the writers have managed to keep it; it tracks its continuity really well, and is very consistent in how it portrays the power levels of the characters. Last night, we saw an episode from season 2 in which short stories are told about each character, and one of them has a story about how he’s sad that it’s X years to the day since his son died. It was pretty heart wrenching; I think both of us had tears pouring down our cheeks afterwards.
It’s weird how I cry far more easily the older I get. I’ve talked to a few friends about it, and they seem to be undergoing the same thing. I wonder what the deal is with that.
Yesterday, I had the task of wiping out a date stamp from a binary file format. I used a hex diffing tool to compare two versions of the same file to see what the offset was for the date, and then slowly nibbled away at an in-place edit using Perl. Normally, I use this as a template for my Perl in-place edits:
do
{
local $^I = '.bak'; //extension for an automagic backup file
local @ARGV = "somefile.txt";
while()
{
s/YEAR/$year/;
print;
}
};
However, yesterday this wasn’t adequate because I lacked knowledge of what byte patterns to throw in a regex. The more I thought about it, the more I was edging towards using read to slurp in the first X bytes, then spew them out into a temp file, spew out 16 bytes, then read from X+16 until EOF and spew that out afterwards.
At that point, it was clear that I should be doing an in-place edit still, but I didn’t understand my little template code correctly. So I sat down and wrote a few different example programs, working out the file handle relationships for in place editing. Eventually, it left me with something like:
open my $FILEHANDLE, "+< ${file}";
seek($FILEHANDLE, $offset, 0);
print $FILEHANDLE "0000000000000000";
close($FILEHANDLE);
And I felt like I’d achieved zen in filehandles.