Haven't posted in a while. In fact, much of my time has been spent with Perl 6, the upcoming version of Perl. And it's sort of been an accident.
A long time ago I stated the Perl 6 Cookbook project and recently I took another look at it. A few people have updated it, but not many. Unfortunately, I realized that the examples wouldn't run due to documentation formatting issue, so I started updating them. In trying to get them to work, I encountered the trimming blanks example.
$string = $string.trim; $string = trim($string); # or more concisely: $string .= trim;
This was a snippet of code which removes whitespace at the beginning and end of strings. I fixed the formatting issues and tried to run the code, only to discover that no one had implemented the .trim method in Perl 6. What's worse, there weren't even any "spec" tests to verify the behavior once implemented. So to make a long story short, I wrote tests for this function and submitted a patch to implement .trim in Perl 6. It's written in PIR (a sort of "object oriented" assembly language which I had to teach myself) and looks like this:
.sub 'trim' :method :multi(_) .local string s .local int start, end, temp, len .local int is_whitespace s = self start = 0 end = length s if end == 0 goto donetrailing trimleading: is_whitespace = is_cclass .CCLASS_WHITESPACE, s, start unless is_whitespace goto doneleading inc start goto trimleading doneleading: temp = end trimtrailing: dec temp is_whitespace = is_cclass .CCLASS_WHITESPACE, s, temp unless is_whitespace goto donetrailing end = temp goto trimtrailing donetrailing: len = end - start s = substr s, start, len .return(s) .end
The patch has been accepted and now I've implemented my first core Perl 6 feature. So why weren't there any tests for this? Because it turns out that .trim was never in the Perl 6 specification. Larry Wall, however, has agreed to the basic idea and it's going in the spec. After a few other issues are hammered out, I'll be extending this (probably .trim_start and .trim_end) and the spec will be updated.
So the Perl 6 spec is being changed and I've added a new core feature to Perl 6 all because I didn't double-check the spec when I should have. Go figure.
Also, it turns out that the test system for Perl 6 needs a lot of work. I started updating it to make it easier to test my changes, but that exposed other bugs in Perl 6. Looks like I'm going to be busy ...