August 29th, 2010

Slimming Down

A couple of things have happened recently which have highlighted ways I can slim things down a bit in terms of the number of things I need to keep track of and change the way I behave.

Thanks to homebrew, rvm, and MacVim I was well on my way to eliminating my use of VirtualBox for doing some of my own “tinkering” using a recent Ubuntu Linux as a familiar environment (I don’t have anything against Linux, it’s just less hassle for me not to have to start up a virtual machine to do some development…)

Ad a recent Toronto Perl Mongers meeting someone asked me about the modules I mentioned in a talk earlier this year and wondered if he could see the code. This had a cascade of effects:

  1. I put the code on GitHub so he could see it.
  2. I installed perlbrew and perl-5.12.1 on my Mac so I could start installing modules without breaking the system perl.
  3. I started updating some of the things I wanted to fix, but somehow hadn’t got around to fixing.
  4. I started goofing around with other Perl modules gratuitiously – for example using Moose to add a couple of attributes to a class despite its apparent ugliness, or common::sense rather than strict and warnings.

It’s amazing how the thought of other people’s eyes on my code are better motivators than my own diligence.

As the Toronto Perl Mongers web site generator was the only project of consequence I was doing on mu Linux VM I finally got to delete the old Linux VM and am now working in a pure OS X environment.

Using Moose has started slimming down my modules, as much of the boiler plate code seems to vanish.

My home tinkering environment has slimmed down, but I suspect the pitcher of beer and chicken fingers at the Perl Mongers meeting has caused some equal and opposite reaction in me!

August 21st, 2010

Restarting vim

Over the years I have managed to squeak by on minimal vi(m) knowledge. Now I’m playing with Rails 3 on my Mac I have an opportunity to get a clean start on an mvim installation. So far in my .vim directory I have:

  • NERD_tree
  • fugitive
  • matchit
  • rails

and they seem to do OK on the new MacVim.

Lots of reading & playing to do now.

August 7th, 2010

map_by_method and awsome_print

I have been playing with some of the gems I installed for my rvm rubies, and the first couple I have looked at are pretty simple – map_by_method and awsome_print.

My trivial code snippet is here:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#!/usr/bin/env ruby

# Trivial class with name and gender methods
class Person
  attr_reader :name, :gender

  def initialize(name, gender)
    @name, @gender = name, gender
  end
end

require 'rubygems'
require 'map_by_method'
require 'ap'

people = [ Person.new('Mike', 'M'), Person.new('Derek', 'M')  ]
ap people.map_by_name
ap people.map_by_name_and_gender

Other blog posts about these gems include http://rpheath.com/posts/246-map-by-method-gem and http://www.rubyinside.com/awesome_print-a-new-pretty-printer-for-your-ruby-objects-3208.html

July 30th, 2010

iPhone 4? iNeed iGlasses!

The iPhone 4 was launched in Canada today. A few people had a new phone at work, and I was keen to see the quality of the Retina display. I suspect that the display is of better quality than my uncorrected eyes can make out. The harder I looked the blurrier everything seemed – books, monitors, my old iPhone’s screen, and the iPhone 4′s display.

Now I need to budget for both an iPhone and some eye glasses. The latter I have been avoiding thanks to manly vanity, but now there’s a good reason to seriously consider correcting my vision.

July 24th, 2010

cider, rvm, and homebrew

The rails installed by cider is a rails 3 beta. As I want to play with some of the examples for rails 2 I thought I should get the most recent ruby 1.8.7 and try to use rvm’s gem sets to get myself a rails 2 world set up

brew install `brew outdated`
rvm install ruby-1.8.7-p299
rvm --default ruby-1.8.7-p299

Was my first step to this, but when I tried irb this is what I saw:

ratdog:~ mike$ irb
no such file to load -- map_by_method
ruby-1.8.7-p299 > q

The cause of this was my ~/.irbrc which had been set up, and which has a whole bundle of useful gems added into it. Most of these are worth a post by themselves, but the suspects were:

  • map_by_method
  • what_methods
  • awesome_print
  • net-http-spy
  • hirb
  • looksee
  • wirble
  • sketches

I set up an rvm gemset and started installing gems:

rvm gemset create rails238
rvm ruby-1.8.7-p299@rails238
gem install map_by_method what_methods awesome_print net-http-spy hirb looksee wirble sketches
gem install rails -v 2.3.8
rvm --default ruby-1.8.7-p299@rails238

All appeared to go well, until I tried navigating to a demo appliction and look at the environment on the default splash screen, which complained about a missing sqlite3 gem. The sqlite3 gem wanted at least ruby-1.9.1 installed, so it was time to install another Ruby.

The ruby-1.9.1-p429 had a problem with gems, but a quick trip to Yahoo! revealed this message, so it was time to install another ruby!

rvm install ruby-1.9.1-p378
rvm use ruby-1.9.1-p378 --default
rvm gemset create rails238
rvm use ruby-1.9.1-p378@rails238 --default
gem install map_by_method what_methods awesome_print net-http-spy hirb looksee wirble sketches
gem install rails -v 2.3.8
gem install sqlite3

Now I can get to work playing with rails! The great thing is that I haven’t compromised my system Ruby, thanks to cider, rvm, and homebrew.

July 14th, 2010

More New Toys

In an effort to get away from using Linux virtual machines on my Mac I am playing with perlbrew so that I can have multiple versions of Perl installed the way rvm lets me do with Ruby.

There seem to be more tools appearing for Perl to help maintain multiple versions of Perl and a controlled subset of CPAN on a system, and now I just need the time and inclination to play with them…

June 29th, 2010

Time to Learn Some More Tools

For a while now I have been put off programming by my daytime experiences, but a recent Ruby5 podcast has whetted my appetite for fun again.

The great thing I found was that the initial install didn’t quite go smoothly…

[Tue, 29 Jun 2010 07:42:01 -0400] INFO: Starting Chef Solo Run
[Tue, 29 Jun 2010 07:42:11 -0400] INFO: Replacing the run_list with ["homebrew", "homebrew::dbs", "homebrew::misc", "ruby", "ruby::irbrc", "ruby::rails", "ruby::sinatra", "node"] from JSON
[Tue, 29 Jun 2010 07:42:12 -0400] INFO: Setting group to 20 for template[/Users/mike/.cider.profile]
[Tue, 29 Jun 2010 07:42:12 -0400] ERROR: template[/Users/mike/.cider.profile] (/Users/mike/.rvm/gems/ruby-1.8.7-p299/gems/chef-0.8.16/lib/chef/mixin/recipe_definition_dsl_core.rb line 59) had an error:
Operation not permitted - /Users/mike/.cider.profile
/Users/mike/.rvm/gems/ruby-1.8.7-p299/gems/chef-0.8.16/bin/../lib/chef/provider/file.rb:118:in `chown'

… so now I have a chance to use rdebug on a real issue, and maybe get to learn something about OS X and the Ruby setup. I’m looking forward to learning more about Cider, and maybe having some fun again.

After a little fooling around with rdebug I decided that the most expedient thing to do was add myself to group 20 and see if Cider would install OK. A quick Yahoo search for adding a user to a group in OS X Snow Leopard led me to this post, and with a quick

dseditgroup -o edit -u mike -p -a mike -t user staff

The install seems to be progressing…

1 July 2010:

My goal was to leave the Snow Leopard install of Ruby alone, and see if I could get the entire thing set up without using sudo. Unfortunately that meant I had to install rvm (from tarball as OS X doesn’t have a git by default) and an rvm ruby to get going. When it tried to install the ~/Developer/… rvm it fell over.

So… use sudo to get cider installed as part of the OS X install and see what it does!

2 July 2010:

It looks like it’s more than just my Ruby which will get dusted off soon, Cider uses RVM which allows multiple rubies and gemsets, and Homebrew to manage installed software on OS X. I ought to know at least what all the programs and gems installed by Cider are, and maybe learn a few of them:

ratdog:~ mike$ brew list
ack		libevent	node		redis		wget
ctags		markdown	npm		rlwrap
fortune		memcached	postgresql	rpg
git		mongodb		proctools	sqlite
kiwi		mysql		readline	tig
ratdog:~ mike$ rvm list

rvm rubies

=> ruby-1.8.7-p248 [ x86_64 ]
ratdog:~ mike$ gem list

*** LOCAL GEMS ***

abstract (1.0.0)
actionmailer (3.0.0.beta3, 2.3.8)
actionpack (3.0.0.beta3, 2.3.8)
activemodel (3.0.0.beta3)
activerecord (3.0.0.beta3, 2.3.8)
activeresource (3.0.0.beta3, 2.3.8)
activesupport (3.0.0.beta3, 2.3.8)
arel (0.3.3)
awesome_print (0.2.1)
builder (2.1.2)
bundler (0.9.26)
configuration (1.1.0)
engineyard (0.3.2)
erubis (2.6.6)
escape (0.0.4)
heroku (1.9.9)
highline (1.5.2)
hirb (0.3.2)
i18n (0.3.7)
json (1.4.3)
json_pure (1.4.3)
launchy (0.3.5)
looksee (0.2.1)
mail (2.2.5)
map_by_method (0.8.3)
memcache-client (1.8.3)
mime-types (1.16)
net-http-spy (0.2.1)
polyglot (0.3.1)
rack (1.1.0)
rack-mount (0.6.6)
rack-test (0.5.4)
rails (3.0.0.beta3, 2.3.8)
railties (3.0.0.beta3)
rake (0.8.7)
rdoc (2.5.8)
rest-client (1.5.1, 1.4.2)
sinatra (1.0)
sketches (0.1.1)
termios (0.9.4)
text-format (1.0.0)
text-hyphen (1.0.0)
thor (0.13.7)
treetop (1.4.8)
tzinfo (0.3.22)
what_methods (1.0.1)
wirble (0.1.3)
June 13th, 2010

Review of Effective Perl Programming

Title: Effective Perl Programming (Second Edition)
Author: Joseph N. Hall, Joshua A. McAdams, and brian d foy
Publisher: Addison Wesley
Date: 2010
ISBN: 978-0-321-49694-2

(Revised and expanded version of my review on Amazon.com)

Effective Perl Programming packs a lot of useful information into a slim and manageable volume – about 425 pages of “meat” in addition to the introduction, other front matter, and back material. There is no “filler” material in the book, which assumes you are already familiar with Perl. The time I have spent reading the book so far has already been handsomely rewarded. All in all the book is well written, accurate, and a delight to read. The authors know their stuff and provide pointers to resources which cover other aspects of Perl well.

The book’s focus on idiomatic Perl sets it apart from most other Perl books. In my experience Perl is a sharp tool, and becoming familiar with its idioms is essential if you want to enjoy cranking out reliable, concise, maintainable code.

Although Perl’s motto may be “There’s More Than One Way To Do It,” the corollary is, “But Most of Them Are Wrong,” or “Some Ways Are Better Than Others.”

The building blocks of the book are 120 items, grouped into thirteen chapters. Each of the items is a relatively short section which ends in a set of things to remember, these items can be used as a cookbook style reference. The first six chapters deal with the basic mechanics of Perl, and the later chapters have a topical focus:

  1. The Basics of Perl
  2. Idiomatic Perl
  3. Regular Expressions
  4. Subroutines
  5. Files and Filehandles
  6. References
  7. CPAN
  8. Unicode
  9. Distributions
  10. Testing
  11. Warnings
  12. Databases
  13. Miscellany

The areas which made this book stand out included:

  • The book doesn’t cover what has already been covered elsewhere, so the material is all fresh and the space is used to investigate topics in reasonable detail.
  • The authors demonstrate a deep understanding of Perl, and have clearly honed their examples and explanations. Well explained areas include: list vs. array, context, local vs. my, Unicode and utf8 handling, and which language constructs are appropriate where. Their experience with Perl in the real world shows in the explanations.
  • The writing and examples are clear and concise. The book’s web site has an errata section which is kept up to date so I could mark up the known errors.
  • Effective Perl Programming revealed some of the features of recent Perl and new modules which I hadn’t noticed or had time to internalize. Damian Conway mentions rehabiting in Perl Best Practices, and this book illuminates some good areas for me to work on.
  • The authors have clearly carefully selected which material to cover, and covered it well. Part of writing idiomatic Perl is to improve the way I think of writing in Perl, and the topics selected by the authors cover about 90% of the things I need to do in my software development using Perl.
  • The book makes effective use of colour in the code examples to highlight the particularly important elements. The quality of the book’s paper and printing as a physical artifact seemed better than most “mass market” technical books I buy these days.
June 6th, 2010

Vacation Time

It was that time of year again.

Time to put all computer related worries out of mind and strike out somewhere to enjoy some down-time with friends and family. This summer’s trip was to Fort Worth to attend the world premier of Jorge Martín‘s opera of Before Night Falls performed by the Fort Worth Opera, catch some of the local tourist sights, go to some of the local galleries, and eat some of the food.

Everything went well, the opera was a delight, and by the end of the week I could have been getting used to the heat. Maybe.

May 12th, 2010

(I Can’t Get No) Satisfaction

Last weekend my wife clipped a review of The Case for Working With Your Hands or why office work is bad for us and fixing things feels good from the Weekend FT. The title of the book and the brief review got me thinking, and I’ll have to read the book when I can get my hands on a copy.

I’m not sure if the author knows what it is like to “fix” software as a job, after many years maintaining software I would probably rework his subtitle to include … fixing real things ….

There are endless things I should do around the house, and I often excuse myself from starting on something by worrying about the quality of the likely result. I hadn’t really thought about the pleasure I get from the process.

Tonight, however, I hope to bask in the fruits of the manual labours of others – the Stick Men hit Toronto tonight!