canspice.org

home about code feeds archives links

Archive for July 2007

OSCON 2007: Taming Legacy Perl, by Peter Scott

I arrived late to this tutorial because I set my alarm for 6:30PM instead of 6:30AM. I know now that it’s possible to wake up, shower, get stuff together, and get to the convention center in 25 minutes.

I arrived to Peter Scott talking about Test::More, which isn’t all that surprising given the topic: taming legacy Perl. I use Test::More in my modules (sometimes not very well), but I did learn that Test::More has functions like eq_hash for hash testing. Other useful modules he touched upon include Test::NoWarnings, Test::MockObject, and Test::MockModule.

Getting a bit away from legacy code, he recommends using h2xs when you’re starting to write a module, if only to get your Makefile.PL for free. Or you could use ExtUtils::ModuleMaker, Module::Start, or Module::Starter. Create a t directory, stick your test programs in there, then if you do perl Makefile.PL; make test it’ll run your tests.

Remember that your tests are programs: use good development practices, use strict and use warnings, keep them small, refactor as necessary, etc.

To test web apps, check out the WWW::Mechanize module, which mimics a webserver, and Test::WWW::Mechanize to test for HTML-y things.

Should you rewrite legacy code? The major advantages to doing this include:

  • you own the new code
  • you understand it
  • you remember it
  • testing is much more fun
  • it probably won’t take as long as you think…
  • …or, not rewriting will take longer than you think

The tutorial seems to be moving away from legacy code and towards good coding habits now… Code should be pretty to look at. You should add comments where you had to think a lot. You can use perltidy to fix up even the worst layout.

Analyzing code can be done using Devel::Cover and Devel::Coverage. These modules look at branching, code line touches, etc., to make sure that your tests adequately cover all possible conditions in your code.

Moving back to inherited code, you have to watch for the apparent level of Perl expertise: does it use Perl-ish structures such as regular expressions or hashes? Does it call parallel arrays or hashes instead of lists of lists? Does it call unnecessary external programs instead of using modules? Does it use my, local, or use? To reduce bloat, look for opportunities to use third-party modules, put duplicated code into subroutines, put duplicated subroutines into modules, don’t optimize for speed before optimizing the code for clarity.

Replace magic numbers with symbolic names. HTML strings should be replaced with a templating system (like HTML::Template or Text::Template). Use the /x modifier to document large regular expressions, or build them up using the qr// operator. Move variable declaration to the latest possible point. Use use strict. Use CPAN.

…and document using POD.

Tags: , , , ,

OSCON, O’Reilly, and the Facebook community

Last week Alasdair Allan started a Facebook group for OSCON 2007. A few people joined.

A couple of days ago O’Reilly started an “official” Facebook group. A few people joined.

What’s the difference? One was started by a member of the community, one was started by a corporation. One was open to whoever wanted to join, one required application and vetting. Here’s the Group Type for the “official” OSCON 2007 Facebook group:

This is a closed group. Members must be invited or approved by an admin.

That doesn’t sound like it’s in the Open Source spirit, does it?

Why didn’t O’Reilly leave the original community-driven group? Why did they feel they had to start their own? Why couldn’t they at least contact Alasdair before trumping his group? And why isn’t the group for the Open Source Convention open to whoever wants to join?

Tags: , , ,

OSCON Day Zero

OSCON Day Zero has come and gone. I arrived in Portland at about 7:15am. Took the MAX to the hotel and dropped off my luggage, as my room was not yet available. I performed my usual routine of mindlessly wandering around looking for somewhere to eat some kind of breakfast (my mindless wandering usually winds Alice up, which is why it’s probably good she wasn’t here for this…!), eventually finding some manner of bakery. When I got back to the hotel Alasdair found me at the front desk, and we went off to spend some money.

Our first place of worship was the Apple Store at Pioneer Place, where we played with iPhones. Shiny. Whizzy. Don’t really want one though…

Then from there we hit Powell’s, where we spent an hour and lots of money — I’ve spent over a hundred bucks there so far, and anticipate spending a little more. Al picked up more books than me but spent less money, showing that he favours quantity over quality.

Lunch came next, with a nice outdoor spot at Rock Bottom Brewery.

Then back to the hotel for a rest, and then out to register for the conference.

Registration went smoothly, but I have to say that the selection of free stuff this year is rather lacking. No more free O’Reilly book. Very small selection of free stuff in the bag — the only non-paper free goodies are a cheap-ish O’Reilly laptop bag, Dice-branded can cooler, a Yahoo! pen, and a Mozilla wristband. The latter is in extremely poor taste, as it’s in the same style as the Livestrong wristbands, as if to signify that open source software is anywhere near as important as cancer research. It’s not even that, as the wristband says “I support the Open Web”. Guess what? Supporting the Open Web (whatever the hell that is) isn’t nearly as important as supporting cancer research, and to suggest otherwise is extremely misguided. Seriously Mozilla, if you want people to show that they support you, give them t-shirts. Giving people wristbands dilutes the purpose of “proper” wristbands the same way that coming up with a different coloured ribbon dilutes the purpose of whatever the original coloured ribbon was for — AIDS research or breast cancer research or something equally important. Not something stupidly mindless as the “Open Web”. Get a clue, Mozilla.

From there was dinner at Kell’s (before which we accidentally and fortuitously met up with Chris), and then a beer in the hotel bar.

Tomorrow will come early, with continental breakfast starting at 7:30, and the tutorials starting at 8:30.

(ps, if you’re wondering why you’re actually seeing this on Monday instead of Sunday, which was actually OSCON Day Zero, it’s because the hotel doesn’t have any free internet access, and the only open wireless access point I can see from my hotel room refuses to give me an IP address, so I’m posting this sometime during the continental breakfast. That’s the reason why future updates will be delayed or come at strange times.)

(oh wait I seem to have some manner of wifi so I’m going to post this while I can)

Tags: , , , , , ,

Off to OSCON 2007

In just over four hours, I’ll be stepping on a plane and flying to Honolulu, the first leg in my journey to Portland. There I’ll be attending my fourth O’Reilly Open Source Convention, or OSCON, an annual get-together of over 2500 open source professionals. Look for frequent updates in the coming days!

Tags: , , ,

Cool Ships…

The first cool ship comes to us from the amazing land of Lego. Working elevators? Check. Catapult airplane launcher? Check. Deck lights? Check. Over 350 pounds and 200,000 bricks? Check.

Alas, it doesn’t look like the Lego aircraft carrier is actually sea-worthy, unlike our second cool ship, which is made from over fifteen million popsicle sticks. The Viking ship has been christened the Sea Heart, which is kind of a lame name. I like Make’s name better:the Good Ship Popsicle Stick.

Tags: , , , , , , ,

HOLY RUBBER DUCKIE

I think you won’t find this rubber duck in your bathtub. Or in your bathroom. Or in your house, for that matter.

Go check out the artist’s site for more pictures.

Thanks, Duran.

Banned By China!

This website is banned by China. That’s right, if you’re in China, the Great Firewall of China blocks canspice.org. Awesome!

Geof, Amy, you’re both blocked as well. Thought I’d test you guys out too. :-)

Tags: , ,

John W. Snow: Whine a little more, please.

Someone call the whaaaaaaaaambulance, we’ve got a terminal case in John W. Snow, the chairman of Cerberus Capital Management, the company that’s buying Chrysler. According to him, a Senate bill that would raise the fuel economy standards to 35mpg for cars and light trucks by 2020 is

a set of standards that are so one-sided that they can’t be met and which have the risk of sinking the U.S. auto industry.

Oh do shut up, Mr. Snow. Your industry is slowly killing the environment, and you have the technology to easily meet these goals. Your bad business decisions are sinking the U.S. auto industry. Why is it that Japanese auto manufacturers aren’t crying about this bill? Why just the U.S. auto manufacturers who insist on building gas guzzling Hummers and Escalades instead of pushing hybrids and alternative-fuel vehicles? Maybe you might want to take some lessons from Toyota or Honda on how to run an auto manufacturing company instead of putting your head in the sand and saying “whaa the government is trying to kill us whaa”.

via the new york times

Tags: , , ,

Formula One to Indianapolis: Seeya, chumps.

Formula One has consistently shat on the Indianapolis Motor Speedway, producing some of the finest debacles in sport known to history. As such, it’s not much of a surprise that Bernie Ecclestone’s extortion-like demands for fees were turned down by IMS CEO Tony George, and Formula One will not be returning to Indianopolis in 2008.

Good. The “track” at IMS was without any charisma and pizazz. Oh boy, it’s got the hallowed yard of bricks. Whoopee. Forgive me for not getting excited.

Maybe now F1 can go to more exciting tracks like Laguna Seca. But Ecclestone seems to have a hard-on for Las Vegas (presumably so he can cozy up to a showgirl or three), so odds are good that we’ll have some boring street circuit to get bored by. Hurray. Look for Hermann Tilke’s name to come up in the near future.

Tags: , , , , ,

Spot the country…

It’s inflammatory and shocking and gets the point across:

Spot the country that’s got the love affair with SUVs. Spot the country that loves their plastics and doesn’t have very good recycling programs set up. Spot the country that’s in the back pockets of the oil and automobile companies. Spot the country that’s killing the planet in more ways than one.

Via duran.

Tags: , , ,