canspice.org

home about code feeds archives links

Archive for July 2006

OSCON 2006: The Girl From Ipanema

In one of Damian’s tutorials he was talking about a poorly-written piece of Perl code that would sit there for ten minutes and, if you were lucky, coredump. He said that it would be nice if Perl played “Girl From Ipanema” and then coredumped.

Since then “Girl From Ipanema” has become the unofficial theme song of OSCON 2006, at least for those of us hanging out on IRC. I thought it reached a zenith last night when Chris got the restaurant’s piano player to play “Girl From Ipanema”.

But no.

This morning on IRC this transpired:

<CanSpice> gnat: any chance you might be able to twist
some arms and get the a/v guys to play Girl From Ipanema
as one of the between-keynotes tracks this morning?
<CanSpice> Before Damian's keynote would be best. :)
<gnat> CanSpice: I'll try.

[snip]

<allegroconmolto> girl from ipanema?
* allegroconmolto sashays.
<CanSpice> OH SNAP
<sirhc> w00t!
<skippy> aloha
<sirhc> go gnat
<CanSpice> gnat, you rule
<sirhc> gnat++++++++
<jgw|dbltree> gnatt && canspice ftw
<CanSpice> dance gnat, dance!

gnat is Nat Torkington, the OSCON Program Chair, and he got “Girl From Ipanema” playing as background music before the keynote addresses this morning.

I think this might go down in OSCON mythology.

OSCON 2006: Day Three Recap

Day three followed day two, as it often does. Since day two ended off with a pub crawl, day three started off with me waking up at seven and then going back to sleep to wake up again at nine. This means I missed the Wednesday keynotes and the first session of the day. I ended up catching Peter Scott’s session titled “Mind Like Water: The Path to Perl Bliss”, which was quite good. It talked about the inner personalities of Perl programmers and how you have to both recognize them and allow them to take over at different times of your project’s lifecycle.

After that came the free lunch. Like last year, the sandwiches are made of rubber bread that make you work.

When that was over I attended “Rock Your Testing World With Devel::Cover“, given by Geoff Young. Another good seminar about how code coverage can help you not only check your code but also help you debug it when it goes wrong. That then took me into “Plagger: Pluggable RSS/Atom Aggregation” by Tatsuhiko Miyagawa, which I didn’t pay much attention to, admittedly.

The last half of the afternoon was taken up by the “Perl Lightning Talks” hosted by Mark-Jason Dominus. As with most lightning talk sessions — which consist of mini talks that last five minutes or so — it was hit or miss. Audrey Tang was a hit, talking about ppencode. She also gave this talk at YAPC::NA, and part of it is on YouTube. Other hits included a talk about Perl::Critic and a bunch of people acting out the module installation process via CPAN.

OSCON 2006: Day Two Recap

On day two of OSCON 2006 I attended Real World Web Services by Scott Davis and More Perl Best Practices by Damian Conway, both of which were good. In RWWS, I don’t remember seeing how to do authentication and authorization over REST, but it must be possible. Damian’s tutorial was a continuation of last year’s tutorial and was quite good as well.

Tuesday night there was reportedly a BoF named “Beers of a Feather”, where someone was apparently organizing a pub crawl, so some of us from IRC went. The lack of any organization didn’t stop us, and we started off in Kells Irish Restaurant and Pub. It was a good start to the evening, especially when the live talent (one guy with a guitar) played Spirit of the West’s Home For A Rest, whose chorus goes:

You’ll have to excuse me, I’m not at my best
I’ve been gone for a month, I’ve been drunk since I left
These so-called vacations will soon by my death
I’m so sick of the drink, I need home for a rest

The night proceeded from there, including hilights from a guy who rapped for us on the street, Chris forgetting his credit card at one of the bars, and a relatively seedy Russian-ish bar to close out the trek.

All in all, a good day.

Edit: I can’t believe I forgot the Tuesday Night Extravaganza! Larry Wall gave his annual State Of The Onion address, making it the tenth one now. It was a good talk about how Perl is growing up and will be ready to “set out on her own” when Perl 6 comes along. Kathy Sierra gave an engaging talk about creating passion in your users. And as always, Damian Conway was excellent with his parody titled “The Da Vinci Codebase”. A Perl one-liner that downloads an illegal prime and converts it into a gzipped program that can decrypt DVDs? Yes please!

Edit2: Flickr user ptufts uploaded a better picture of Damian Conway’s twisted twisted code.

OSCON 2006: Day One Recap

Day one of OSCON had me attending two tutorials: The 7 Principles of Better API Design by Damian Conway and Higher-Order Perl by Mark-Jason Dominus. I’ve seen both of them give tutorials before and was expecting the world of them, and they delivered. Damian’s talk wasn’t mindblowing, as his typically are, but was full of incredibly useful information towards cleaning up the public interface of modules. MJD’s was, I have to say, a good example of an MJD talk — extremely interesting, given at a level where you’re neither being talked down to nor being hit with incredibly difficult information, and he had a couple of good rant-like digressions. If you want to get him wound up, say something about the pluralisation of “octopus” is “octopi”.

The wireless connectivity was non-existant in my first tutorial but was fixed for the second. Wireless good.

For dinner a group of people went to the Rogue Ale Public House, where I had a Hazelnut Brown Nectar (quite nice) and a Chocolate Stout (not bad). I preferred the Hazelnut, mostly because I’m not that much a fan of bitter beers.

After the Rogue we headed back to the Oregon Convention Center for a game of Werewolf, which was very fun. I got killed by the villagers early in the first game by someone who said they were the Seer (who has special powers and can find out who’s a werewolf and who isn’t). They weren’t the Seer, I wasn’t a werewolf, and I was out. It was still fun watching how a bunch of (seemingly) intelligent geeks get swayed by mob rule so easily. I made it relatively far into the second game, even going so far as to accuse someone of being a werewolf who was actually a werewolf, but my fellow villagers didn’t vote for him, so I subsequently got killed. Guess they thought that I was being too accusatory and was therefore a werewolf, which I wasn’t.

The werewolves won both games. And fun was had by all.

OSCON 2006: Higher-Order Perl, Mark-Jason Dominus

Everybody says that Perl is a lot like other languages, especially C, sed, and awk. That may have been true in the early days of Perl, but it’s not really that true now. Perl has a lot of features that weren’t previously available and that you might not know about. You may have been writing C programs in Perl all along, and now it’s time to do better: start writing Perl programs in Perl. Three things talked about in this tutorial that will help you write better Perl are caching and memoization, iterators, and parsing.

Many functions depend only on their arguments, so why bother having those functions redo potentially compute-intensive calculations? Once you’ve calculated the result, you should cache it, or save it in memory, so the next time your function is given the same input it can do a simple memory lookup. An example of this is sorting dates of the form “May 17, 1998″. A naive way to sort these dates would be to convert them into a sortable string or number, then sort that way. You could use YYYYMMDD, so that “May 17, 1998″ would be converted to 19980517, which you can then use as a number to sort against other dates. However, this conversion process isn’t free, as you have to split up the string into month, day, and year, then convert the month into a number, and join it all back together again. Why bother doing that twice? If you’ve already converted “May 17, 1998″ to 199980517, why not store the result so you don’t have to do that conversion again? Simply stick the result into a cache structure (in Perl, that’s probably going to be a hash), and next time through, check to see if a result exists in the cache first, and if it doesn’t, then do the calculation.

Doing this to all of your code is fairly easy, but it’s formulaic and can be done automatically by using the Memoize module. Memoize isn’t for everything, so don’t use it for everything. A good example of where it can bite you is random number generation. You want the function to calculate a new random number each time, you don’t want a cached result sent back to you.

Switching tracks a bit, iterators can be seen as an object interface to a list, where you can move through the list by successively retrieving the next object in the list. This helps save on memory because the iterator doesn’t need to keep the entire list in memory, only the list members that it’s already seen.

Perl programmers are used to using iterators whether they realize it or not. A filehandle is an iterator that allows you to step through a file one line at a time.

Iterators have to retain state between calls, because they have to remember where it is so it can get to where it’s got to get next. One drawback of iterators is that they’re like toothpaste tubes — it’s easy to get the data out of it but hard to put back in. It’s difficult to go back to the beginning of your list and start again. If you’d want to do that, you should use a stream, which is essentially the same as an iterator. The only difference is mainly in the interface, as a stream can be used to look ahead at what’s in the list, and an iterator can be used to retrieve what’s next in the list.

Parsing is the process of taking unstructured input and turning it into a usable data structure. To write a parser it’s usually easiest to write a grammar, that is, some set of instructions that describe how different parts of the input are going to be made up. These grammars are usually described in Backus-Naur form, or BNF. What you can then do is build an iterator that walks its way through the input string to generate tokens that match the grammar, thus parsing the input string into a usable data structure.

It turns out that Perl isn’t much like C or awk or sed, it’s more like lisp. And lisp has been around a lot longer than Perl has, so it would be very useful to talk to lisp users and discover their learnings as they’ve gone along developing in lisp. The only problem is that nobody wants to do that because lisp users are really bitter. Luckily for us, Mark-Jason Dominus has done that (talked to lisp users, not got really bitter), and his Higher-Order Perl is the fortunate result.