Ruby Refactoring

Speaking of refactoring, here’s the best talk on refactoring in the Ruby world, via Katrina Owen:

Pay special attention to the way she manipulates her slides to show the refactoring she’s doing. That’s half the magic of the piece.

Ben Orenstein’s recent “Refactoring from Good to Great” is also worth a view, with a fun live demonstration.

Quelle est 'idempotence'?

“Idempotent” is a big word. It’s one of the four-dollar words thrown around by functional programmers, and it confuses people – including functional programmers. This is because we don’t use it consistently.

Well worth a read, with plenty of analogies to help explain it to you. You’ll also learn the word “nullipotent”.

The Problem With Perl Refactoring

Refactoring is an easy concept, ultimately. You’re rewriting code to make it cleaner or faster or more clear. The end result is still the same, but the way you get there is different.

(Yes, that’s a vast simplification, but that’s all we need relevant to this post.)

Refactoring code involves finding the weak parts of the code and rewriting them. Having a suite of tests to back you up on this is a good thing. Heck, it’s a necessary thing.

Ultimately, though, knowing how to refactor code comes from two things: Language knowledge and experience. You can refactor code all day and go in circles. It’s the knowledgeable refactorings that bring added value to the code base.

That’s why I bristled so much in watching this “Perl Refactoring” video. There’s a serious problem in the Perl community and that’s its over-reliance on the CPAN for everything. Searching for a module to refactor code for you is silly. Refactoring takes a knowledge of code. In the case of Perl, that might mean using a module from CPAN in lieu of some hairy code you wrote yourself but that is potentially unstable and not time tested. But looking for a CPAN module that will point out what to refactor, or even hoping such a beast would do the refactoring for you is just silly.

Here’s the key to refactoring: You need to know the language and know the concepts behind it. No automated refactoring machine will save you. You have to do the work.

Hello, World

This is a first test of my new Octopress-driven blog to discuss the finer points of computer programming geekery.

I’m a Perl programmer by trade, but have spent a lot of time in the last year learning Ruby, Ruby on Rails, Elixir, and iOS programming. Call it a programming mid-life crisis, if you will.

I’ve started this blog to ramble on about the things that interest me in that world but that regular readers of the main blog,, which is so old in internet terms that I still have the “www.” in front of it.

Just to test how this blog handles code excerpts, here’s a little something I wrote last night in Elixir:

Part of a Classic Guessing Game
defp guess(actual, low.._high, c_guess) when c_guess > actual do
  IO.puts "Is it #{c_guess}"
  new_range = (low..c_guess)
  guess(actual, new_range, take_a_guess(new_range))

Frustratingly, code highlight for Elixir is not available in pygments.rb. It is available in the main Python-based pygments highlighting system, so perhaps we’ll see it ported over someday soon…