Wednesday, December 22, 2010

Included in the End-of-Year message from Caltech President Chameau is this quote from Einstein, delivered in December 1930, on his first visit to Caltech.

"To you all, my American friends, I wish a happy 1931. You are well entitled to look confidently to the future, because you harmoniously combine the joy of life, the joy of work, and a carefree, enterprising spirit which pervades your very being, and seems to make the day's work like blessed play to a child."
---- Albert Einstein, December 1930

May the spirit of joy pervade your life and your work in the coming year! Let us all look confidently and move boldly into the future. Happy Solstice! Merry Christmas! Happy New Year!

Sunday, December 19, 2010

ORM -- database abstractions

I've just learned of DBIx::Class::CDBICompat, a Class::DBI compatibility layer for DBIx::Class. Awesome.


DBIx::Class features a fully featured compatibility layer with Class::DBI and some common plugins to ease transition for existing CDBI users.

This is not a wrapper or subclass of DBIx::Class but rather a series of plugins. The result being that even though you're using the Class::DBI emulation layer you are still getting DBIx::Class objects. You can use all DBIx::Class features and methods via CDBICompat. This allows you to take advantage of DBIx::Class features without having to rewrite your CDBI code.

I have inherited an app based on Class::DBI, but I'm not terribly familiar with Class::DBI. So far, the SQL snippet approach is annoying. There are lurking bugs (in our code, not Class::DBI), but mocking and fixing with CDBI is proving to be a pain. It's good to know that if I rewrite all the DB layer in DBIxClass over the holidays, that I'll be able to shim some of the old code onto it through a compatibility layer.

Related topics:

DBIx::Class vs Class::DBI vs Rose::DB::Object vs Fey::ORM by fRew
PerlMonks discussion
Class:DBI vs DBIx::Class vs Rose::DB::Object
"DBIxDM is very interesting and Laurent Dami helps the DBIC team maintain SQL::Abstract – but he also doesn’t manage to market it to save his life so very few people have heard of it." -- Matt Trout
Rose::DB -- hand coded to be fastest of the 4?
Marlon suggested looking more deeply into the DB benchmarks.
"You really should run the benchmarks of Rose::DB vs DBIC. Your database layer is usually your slowest in your entire application, so that’s important. RDBO is also the ORM we use at because speed is important at this level. I’ll be interested in looking at what the new revision of DBIC with Moose does in that arena. On a side note, I agree that the generative queries are excellent on DBIC."


2006 discussion of Rose vs DBIx, by the Rose Author.

Perl 2011: Where are we now?

Piers Cawley wrote an excellent forward looking piece The Perl Future in January 2009. As we approach the two year mark, how have we fared? He talks about perl 6, perl 5.10.0, aka "perl5 version 10," Perl Enlightenment & the rise of Moose, and "on frameworks and the future."

Where are we now?

Perl 5.12 is out, as scheduled, on time -- two years of work representing 750,000 lines of changes over 3000 files and 200 authors. Deprecated features of perl4&5 are finally marked as such. More Unicode improvements. Features improvements for the Y2038 bug (is epoch time 64 bit now ?) Includes pluggable keywords and syntax. A new release schedule means stable releases come out in the spring, followed by a .1 fix release, then monthly releases (on the 20th) for new bug fixes.

Perl 6 released a real, honest to goodness release candidate. Rakudo Star, "A useable perl6 release" was released in June, aimed at "Perl 6 early adopters." Rakudo star has seen monthly updates, most recently Rakudo Star 2010.11 released in November 2011. Rakudo Perl is a specific implementation of Perl 6 the language, this Rakudo Star 2010.11 release includes "release #35 of the Rakudo Perl 6 compiler, version 2.10.1 of the Parrot Virtual Machine, and various modules, documentation, and other resources collected from the Perl 6 community."

A year-and-a-half of the Perl Iron Man blogging project has seen a flurry of posts from nearly 250 perl bloggers! We've seen advocacy, snippets, whining, and community. I've seen a lot more Japanese language perl posts -- folks happy to use perl, python and ruby and pull the best from each.

I now find it strange and unsettling to meet self proclaimed perl programmers who don't use Moose. If you haven't played with it (and it does feel like playing, it's liberatingly fun), go do so now. I'll wait.

I don't know about you, but I just switched from one startup using perl to another startup using perl. Awesome perl folks are hard to find, they're mostly already busy doing work they love. Why are we using perl? -- because perl works, it scales with developer time, and perl is beautiful.

Piers mentioned frameworks -- yes individual frameworks are important but the vast armada of options available at CPAN as a whole provide an immense multiplier on developer productivity. It's so massive, it is easy to overlook -- Doesn't everyone have a massive, distributed, user-written body of code with excellent testing methodology available at the touch of a button?

Merry Christmas to all!

However, if you look at the good parts (O'Reilly haven't announced "Perl: The Good Parts", but it's a book that's crying out to be written), there's a really nice language in there. Arguably there's at least two. There's the language of the one-liner, the quick throwaway program written to achieve some sysadmin related task, and there's the more 'refined' language you use when you're writing something that is going to end up being maintained.

I think it's this split personality that can put people off the language. They see the line noise of the one liner school of programming, the games of Code Golf (originally called Perl golf, the idea spread), the obfuscated Perl contests, the terrible code that got written by cowboys and people who didn't know any better in the dotcom bubble (you can achieve an surprising amount with terrible Perl code, but you will hit the wall when you try and change it) and they think that's all there is.

But there is another Perl. It's a language that runs The Internet Movie Database, Slashdot,,, LiveJournal and HiveMinder. It's a language which enables people to write and maintain massive code-bases over years, supporting developers with excellent testing and documentation. It's a language you should be considering for your next project. It's also something of a blue sky research project - at least, that's how some people see Perl 6.


Wednesday, December 15, 2010

A story of one man's journey to Vim Nirvana (Vimvana). For those of you stuck on Monday, keep trying you'll make it.
I was watching a violinist bow intensely and I had this thought: I probably have as many brain cells devoted to my text editor as he does to playing his chosen instrument. Is it outlandish to imagine that an MRI of his brain during a difficult solo wouldn’t look much different than mine while manipulating code in vim?

Consider, if you will, the following montage from one vimmer’s journey.


Tuesday, December 14, 2010

Perl Advent Calendars

It's Advent Calendar time in the perl ecosystem! Start each day with a delicious treat of knowledge.

I've found a half dozen english language perl advent calendars, starting with the original perl advent calendar. For extra fun I've included another half dozen Japanese language calendars -- I can still read the perl it's just the prose that is lost in translation.

Perl Mongers Perl Advent calendar
Catalyst Advent Calendar -- The Catalyst Web Framework
Perl Dancer -- the Dancer mini web framework
Ricardo's 2010 advent calendar -- a month of RJBS
UWE's advent calendar - a cpan module every day.
Perl 6
Last Year's Plack calendar
For the adventurous: Japanese Perl Advent Calendars, 8 different tracks!
Hacker Track
Casual Track
English Track
Acme Track
Win32 Track
Meta Advent Calendar Track
Symbolic Programing Track
perl 6

One bonus list, for the sysadmin in your life:

SysAdvent - The Sysadmin Advent Calendar.

Monday, December 13, 2010

Vimana : cpan module to automate vim plugin installation

VIMANA! The Vim script manager. A cpan module for downloading and installing vim plugins! It works with .vim files, archive files (zip, rar), and vimball formats. By c9s / cornelius / Yo-An Lin. caveat: the "installed" command only recognizes plugins installed via vimana.

Cornelius's perl hacks on vim presentation has been on slideshare for two years. It covers "why you should improve your editor skills" -- ranging from "stop moving around with the arrow keys" to advanced commands and plugins. He's written quite a few vim plugins and quite a lot of cpan modules. Props!

Vimana Example:

% cpan Vimana
% vimana search nerd
nerd-tree-&-ack     [utility]      Adding search capability to NERD_Tree with ack
the-nerd-tree       [utility]      A tree explorer plugin for navigating the filesystem
nerd-tree-project   [utility]      It tries to find out root project directory, browse project file with NERD_tree.
the-nerd-commenter  [utility]      A plugin that allows for easy commenting of code for many filetypes.
findinnerdtree      [utility]      Expands NERDTree to file in current buffer

% vimana info the-nerd-tree
#... shows the install instructions ...

% vimana install the-nerd-tree
Plugin will be installed to runtime path: /home/andrew/.vim
Package the-nerd-tree is not installed.
Downloading plugin
 - Makefile : Check if makefile exists. ...not ok
 - Meta : Check if 'META' or 'VIMMETA' file exists. support for VIM::Packager. ... - Rakefile : Check if rakefile exists. ...not ok
Package doesn't contain META,VIMMETA,VIMMETA.yml or Makefile file
Copying files...
/tmp/yohBObI3iy/ => /home/andrew/.vim
Updating helptags

There are quite a few plugins mentioned in the presentation. I've listed the ones I'm interested below. I'll be installing and reviewing them soon. Slide 120 begins a nice section on advanced movement keys. Slide 135 has a list of the variables controlling the perl syntax highlighter.

Perl folding variables:

" set :help folding for more information
:set foldmethod=syntax              " enable syntax based folding
let perl_include_pod=1              " fold POD documentation.
let perl_extended_vars=1            " for complex things like @{${"foo"}}
let perl_want_scope_in_variables=1  " for something like $pack::var1
let perl_fold=1                     " enable perl language based folding
let perl_fold_blocks=1              " enable folding based on {} blocks
---- slide 135

Vim Plugins:

Exciting vim plugins to check out from Reviews and usage information to come in future posts. I'm excited to try Cornelius's updated OmniCompletion helpers.

How does this compare with, included with vim?
Run database queries from inside vim. I skipped past this the first time around, but now I see that it will let you copy the query directly from your source language, apply that languages string mechanics to get the output string and then prompt for bound variables. interesting!
Allows a handy shorthand mapping to search for files/buffers/etc.
the NERD tree
updated file listing explorer
You're already using this, right?
the NERD commentor
improved commenting, under current development.
a ctag integration that shows tag information for the current file / source code browser
"The most downloaded and highest rated plugin on"
Buffer Explorer / Browser -- easily switch between buffers.
Git commands within vim.
a git plugin for vim ( with a git tree menu like NERDtree ), by c9s.
Updates to vim omnicompletion for perl:
Demonstration video
Automatically opens popup menu for completions

TEDxCALTECH -- Friday, January 14, 2010

"Feynman's Vision -- The next 50 years"

TEDx, the independent TED event series is coming to Caltech in January. TEDx events are inspired by TED and use the same plans and speaking formats. I'm surprised I haven't heard more buzz about this event. I wasn't able to get into TEDxUSC, the first of the TEDx events. I'll be volunteering for the event and hope to see you there!

Will we see coverage of Feynman's vision of the "race to the bottom" -- his challenge to his engineering and scientist peers to work together and compete to see how small we can go in nanotech. Will anyone from Professor Tai's micro-machine lab be speaking? I'm sure we'll see interesting wetware - bio/cs/eng research, given the Institute's focus on Bio over the past decade.

You won't know until you go! (Or until you check the speakers tab)

Feynman's Vision -- The next 50 years.

TEDxCaltech is a community of people who are passionate about sharing "Feynman’s Vision: The Next 50 Years." If that sounds like something you want to be a part of, complete and submit the application below. Due to limited venue space, we cannot approve all applicants instantaneously. If you are approved, you will receive an email shortly either inviting you to register for the event, or letting you know that you are on the waiting list. The registration fee is $25 for Caltech students; $65 for Caltech faculty, staff, postdocs, alumni and JPL; and $85 for all others. The all-inclusive day will begin with breakfast and will be punctuated with generous breaks for food and conversation with fellow attendees. It promises to be an exciting and entertaining intellectual adventure—a time to unplug from the day-to-day routine. You won’t want to miss a minute!

Registration opens at 8:00 am, doors open at 9:30 am, talks conclude at 6:00 pm and will be followed by a reception. Parking is free.

Thursday, December 9, 2010

perl, tags, and vim : effective code browsing.

Adding a tags file to vim makes for an effective code browser for perl.

I've just started a new job, so I have a large new repository of perl code and modules to familiarize myself with. I've taken this as an opportunity to refresh my tag-fu in vim. After creating a tag file with ctags [exhuberant ctags], I can now jump around my whole perl repo from within my vim session.

The -t command-line flag to vim opens files by tag (module) name, e.g. vim -t My::Module::Name. Within a vim session, I jump to the definition of a function by hitting ctrl-] with the cursor over a usage of the function, even if that definition is another file! Ctrl-t and I'm back where I started.

Today I found the -q flag to ctags, which adds the fully qualified tag for package methods, e.g. My::Package::method_1, which aids with long package names and the ctrl-] key. FTW!
I have this set of ctag flags aliased as "ctagit":

ctags -f tags --recurse --totals \
--exclude=blib --exclude=.svn \
--exclude=.git --exclude='*~' \
--extra=q \
--languages=Perl \

In my .vimrc file, I defined the tags search path as ./tags, tags,~/code/tags ;, this will look for a tags file in the directory of a loaded file, then the current directory, and then a hardcoded path in my code area.

" [ .vimrc file ] " set tag search path: directory of current file, current working directory, hard-path set tags=./tags,tags,~/code/tags

More info on using tags in vim is available in :help tags. I've found the following commands useful.

ctrl-]jump to tag from under cursor
visual ctrl-] jump to tag from visual mode
:tag tagname jump to tag tagname
:stag tagname split screen and open tagname
:tags show the tag stack, '>' labels the current tag
:ctrl-t jump to [count] older entry in the tag stack
:[count]pop jump to [count] older entry in tag stack
:[count]tag jump to [count] newer entry in tag stack

To configure vim to treat ':' (colon) as part of the keyword to match Long::Module::Sub::Module package names, add it to the iskeyword setting. I have multiple perl filetype hooks stored in files in .vim/ftplugin/perl/. These filetype hooks are enabled with the filetype plugin on directive in my main .vimrc file.

" [ .vimrc file]
"enable loading the ftplugin directories
filetype plugin on
" [ .vim/ftplugin/perl/keyword_for_perl file]
" Append : to the list of keyword chars to allow completion on Module::Names
set iskeyword+=:

The same effect could be conjured directly in the .vimrc file via autocmd:

" append colon(:) to the iskeyword list for perl files, to enable Module::Name completion.
autocmd FileType perl set iskeyword+=:

My Configuration files are available in the spazm/config git repository on github.