Started reading Perl Moderne

April 5, 2011

I picked up a copy of Perl Moderne the new book by France’s Perl Gang of Four, Damien Krotkine, Sébastien Aperghis-Tramoni, Jérôme Quelin, and Philippe ‘BooK’ Bruhat, and have just started reading it.

Perl doesn’t seem to have the presence in France that it does in the English-speaking world. I hope this book helps change that, because it’s clearly-written, commute-friendly book which covers a lot of ground, from installation to Moose. Non-French Perl hackers can pick up their professional vocabulary here too. (Make your admirers swoon with desire by murmuring table de hachage like Morticia Addams did Gomez: “Tish! You speak French!”)

I am puzzled about a seeming omission in their first-chapter discussion of editors and ready-to-install binaries: there is no mention of Active State’s Komodo IDE or ActivePerl. Perhaps because Komodo is payware? I’ll ask next time I see one of them.

Advertisements

Figuring out map coordinates

April 5, 2011

Many sites use vendors other than Google for their mapping needs. These may use projections that dish up non-GPS coordinates. Here’s a rough way to figure out what these coordinates are and how to convert them, without returning to school for a graduate degree in geoinformatics.

  • Make a note of the unfamiliar coordinates and the street address.
  • Search by street address at Google Maps. Get the coordinates by right-clicking at the very tip of the red indicator and choosing “What’s here?”
  • Hop over to the World Coordinate Converter web site. Choose ‘*GPS (WGS84) (deg)’ from the drop-down in the upper box (if it’s not already selected) followed by the Google Maps coordinates.
  • Fool around with target systems in the lower box. Choose some likely candidates and click Convert. Keep this up until you get results close to the mystery coordinates (don’t count on identical).
  • Click on the ? next to the coordinate system name you chose. Put on your reading glasses and find the link in the popup to spatialreference.org. Click on it. This will give you the WKID (Well Known ID) of the projection, in the form of EPSG:\d+.
  • The WKID for the Google Maps projection is EPSG:4326 (http://spatialreference.org/ref/epsg/4326/).
  • Obtain the program gdaltransform by installing the GDAL utilities on your friendly *nix box.
    On Fedora, it’s apt-get install gdal-bin

  • Now the magic incantation:

    echo $x $y | /usr/bin/gdaltransform -s_srs [/source] -t_srs [target WKID]

    You will get your desired coordinates. Gingerly carry these over to Google Maps and verify that you’re in desired vicinity. The coordinates may be longitude-first, so you may need to reverse their order.

Further reading:


Happiness is a test suite.

March 9, 2011

Today I am grateful for my test suite. I had to install my handiwork on a production box for the first time today, and the test suite made short work of identifying and fixing problems. It’s astonishing what testing for the seemingly obvious will catch.

A test suite is a courtesy to the next sap charged with the task, as well. Why make them hate you and your mass of bugs any more than strictly necessary?


Will SWAG for food

March 2, 2011

Why is it that when I am asked to estimate a project, I switch into abused-dog mode? My first instinct is to dive under the desk and whimper, which I promptly suppress in favor of other, hopefully more productive approaches.

So the last time I was asked, I stewed about it for 24 hours, talked with management-experienced friends, then finally did the sensible thing: I went to a colleague and ‘fessed up. “I’m not that good at this. And not only am I not good at this, I can’t calm myself enough to make myself good at this. May I get some help?” Why certainly. So yesterday we started to break down my project into finer detail. I drew up a spreadsheet with tasks, estimated each on a story point scale, added it up, and multiplied by 3 to account for the fact that I’m not Donald Knuth. I added a column for actual time, and hopefully, over time I will get an idea of the value of my own personal human coefficient, which I suspect will be rather high.

I reviewed Andy Lester’s Preventing Crisis talk, and asked my former colleague Buddy Burden for the story point scale in use at Rent.

Story Points The Buddy Scale The Dave Scale
dink “We’ve already spent more time talking about it than it would take to just do it.” An issue added that is quick to implement i.e., < 1 hour, equivalent to .25 story points
1 “Pfft. That’s nothing.” hours
2 “That’s not too bad …” hours to a day (or two)
3 “Not too awful, but non-trivial.” a few days

5 “This is some real work.” days to a week (or two)
8 “This is surprisingly difficult.” a few weeks
13 “This really sucks.” weeks to months
21 “There’s no way one person could do this by themselves.” weeks to months for multiple people
40 “This is a major project.” months for multiple people
100 “If they truly understood how heinous this was, they wouldn’t want to do it any more.” months for a lot of people


Web::Scraper

February 27, 2011

Lately I’ve been using the nifty Web::Scraper by the prolific Tatsuhiko Miyagawa. It exposes a compact DSL of three words, process, process_first and result, to scrape sites based on XPath expressions or CSS selectors:


use Data::Dumper;
use Web::Scraper;
use URI;

# Find the <title> element and place its content
# in a hash reference with the key 'title'

my $scraper = scraper {
process '//title', title => 'TEXT';
};

my $data = $scraper->scrape(
URI->new('http://www.google.com')
);

warn Dumper $data;

Gets you

$VAR1 = {
'title' => 'Google'
};

You can also have it return an arrayref for an element, pass in callbacks, or nest scrapers.

I forked the code and added a hashref option, nice when paired with a callback that returns a hash.

scraper (a disguised constructor) and the keywords are exported into the caller’s namespace. If the potential for collision concerns you, wrap up scraper instantiation in a separate module.

The documentation is a bit thin, so in addition check out Miyagawa’s presentation slides.


First foray into Moose

February 26, 2011

As a startup’s sole Perl programmer I have been feeling the pressure to get things done more quickly. Whipping up a codebase from scratch, or from a chicken-scratch prototype, is very different from propping up a brittle hulking legacy codebase. I began to feel limited by Perl’s object model simply because of all the keystroking and the attention to implementation details. So yesterday I gave Moose a little try.

A well-designed toolkit always gives the new user one very useful thing right away, a small but immediate reward for the effort of trying out a new way of doing things. Moose does this with the keyword has. Describe your attributes in excruciating detail and poof! you’ve done away with mounds of keystroking. Very nice. Already a quick little boost before lunchtime, and this time not from my coffee cup.

I also noticed another side benefit. Writing classes declaratively is an aide to thinking more abstractly. The little word has puts the emphasis directly on the interface. A language and its user have a symbiotic relationship–the user writes in the language and the language guides the user’s thinking. Moose enhances Perl’s ability to lead, follow or get out of the way at the right times by letting you shift gears to greater abstraction. I found this very pleasant.


!=

February 25, 2011

Information is not knowledge. Knowledge is not wisdom. Wisdom is not truth. Truth is not beauty. Beauty is not love. Love is not Perl. Perl is THE BEST.

D’après Frank Zappa, who originally said this of music.