Learning Ruby – Day 7

Day 7, playing catch-up.

I’m continually impressed with how concise the Ruby language is. As I mentioned in Day 4, Ruby frowns upon loops. I’m getting the impression Ruby also frowns upon taking up 2 or more lines to describe an action. Slagell’s examples of doing something a traditional way take up multiple lines, his here’s-a-better-way examples are single line. If we compare writing code to writing words and say each a chunk of code is a paragraph and each line of code is a sentence. Writing Ruby is more like dialog than narrative.

Note to self:
In Ruby, double quotes acknowledges backslash-escaped characters, i.e. "n" = new line. Single quotes will not, i.e. 'n' = n. Same is true for evaluating expressions within #{...}

Two Cool Things in Ruby:

  1. Chained Assigment
    Want to give a number of variables the same value?
    DaveSpeaks = JoeSpeaks = KatSpeaks = FrankSpeaks = "English"
  2. Multiple Assignment
    Want to quickly set the values of multiple variables at the same time?
    DaveSpeaks, JoeSpeaks, KatSpeaks = "English", "Dutch", "German"

The start of the day has quite a bit on binary numbers. I’m not sure when binary arithmetic will come in handy (a position I also expressed regarding Jr. High Algebra) but it’s nice to know it’s here when the need arises. The example Slagell offers at the chapter end feels like a band-aid for a poorly designed system. If any of you following along can provide a comment on when it’s beneficial to use binary arithmetric, I’d be extremely grateful.

As I finished up today’s exercises, Bic Runga’s ‘Listening for the Weather’ came through my iTunes. What an excellent way to wrap up Day 7.


This post documents my journey through Sam’s Teach Yourself Ruby in 21 days. I’ll be joining Al Abut in his effort to learn Ruby and blog along the way.


Kayak and PinPoint Changing the Face of Online Travel

A couple years back, I helped Orbitz.com redesign their shopping process. During that time, if you wanted to book travel the major players were Expedia and Travelocity, with Orbitz aiming to be the more usable, better-looking alternative.

Today, those three players are equally mature and equally less than compelling. They don’t capture all airlines and have yet to offer the recreational traveler’s dream: give me the cheapest flight to Brussels, anytime, any day, in the next 1, 3, and 6 months.

Enter Kayak.com. Think of it as Froogle for travel. Just the bare-minimum needed to start a travel search. If you want something a little sexier, check out Pinpoint Travel. Pinpoint uses Kayak’s engine and leverages the new AJAX web application model making a very interesting and helpful interface – like Google Suggests. Also, by asking me questions about my personal preferences, Pinpoint does an excellent job of keeping me engaged while it’s searching.

On the downside, AJAX relies heavily on Javascript so Pinpoint isn’t accessible and for some odd reason neither is Kayak.

More Gets You to Better

As I mentioned in my interview at Podcast411.com, I had an art professor who believed everyone had 5,000 bad drawings in them. Five thousand drawings bad drawings before the good ones could come out.

This perspective is re-iterated in Throw More Pots over at Crossroads Dispatches.

In this same token, I’m a firm believer every organization needs a playground, a skunkworks, a sandbox. Whatever it’s called, it’s a mentality where people can develop a million small ideas to find the ones that work. Whether drawings or pots or business models.

With the relative low cost of website development, in comparison to traditional television marketing, there’s a huge opportunity to try a million different small (potentially better) campaigns and cumulatively get the same return – if not a greater return.

Spring Cleaning at the Work Better Weblog

So we’re back. My apologies if you stopped by over the last couple days to find us not here. I was working on a new visual presentation for the website and the CMS ended up not cooperating.

Everything is mostly back to normal now. Though for the next few days, if you hit the site, verses reading the RSS feed, you’ll still see the somethings moving around.

What Price Garbage Avoidance

We’ve got a Rainbow Foods just south of us and a Cub Foods just north of us. Both are just on the border of walking-distance away (that’s a different story). At both stores, I’m struck by how much of we don’t see, how many aisles we don’t walk down, and how much crap we don’t buy. The other day, looking for a change, we picked up a few things at the local Whole Foods store. Though there were still huge sections we avoided, I felt the high fructose corn syrup content of the store was a factor of 10 lower. Refreshing.

The price difference between the Rainbow and the Whole Foods made me wonder:

In the age of scarcity, price is the value of receiving something wanted.
In the age of plenty, price is the value of filtering out something unwanted.

This filtering-out is why Tivo can charge a monthly subscription and why AOL is marketing themselves on virus, spam, and pop-up protection.

I was listening to my backlog of SXSW ( ) music tonight when Rob McColley’s TeeVee came through my iPod. He sings, appropriately:

’cause the free stuff you get these days
I’d pay to keep away from me.

Learning Ruby – Day 6

Day 6, How to deal with files and other data streams.

What’s a reliable way to get the last item in an array? ask for the -1 item, i.e. array[-1].
Finally, a logical reason to start arrays at 0 rather than 1 – so we can count backwards.

Looks like the “then” part of an “if…then” statement can come first. As in this example from the book, removing a leading zero from a decimal number.
avg[0,1] = '' if avg[0, 2] == "0."

This will take some getting accustomed to. I’m more familiar with it written this way:

if avg[0,2] == "0."
avg[0,1] == ''
end

To accommodate When Bad Things Happen, Ruby has a pretty cool construct:

begin
#...
rescue BadThing1Happened
#...
rescue BadThing2Happened
#...
end

Two cool things here; first – this seems like a simple way to write more readable code – error conditions or otherwise, second – the word “rescue”, makes you feel like a superhero for catching Bad Things. Incentive enough for writing better code.


This post documents my journey through Sam’s Teach Yourself Ruby in 21 days. I’ll be joining Al Abut in his effort to learn Ruby and blog along the way.


Learning Ruby – Day 5

Day 5 is all about objects and their methods.

Remember a few months back when Apple introduced the Shuffle? Everyone was up-in-arms about it’s lack of screen and how it was useless an mp3 player without a screen is. When in-fact, the lack of screen simplifies and improves the device a great deal.

Ruby is like that; elegant, well thought out, useful, challenging convention. Case in point:

Methods names can end with ‘ =’. Conceptually treating a method’s values as variables. It not only saves keystrokes in comparison to the traditional methodName(value) convention – it more accurately maps to what’s being described.

Add to that, a built-in method for creating read & write methods – attr_accessor, an I’m understanding why Ruby is called the Programmers’ Best Friend.


This post documents my journey through Sam’s Teach Yourself Ruby in 21 days. I’ll be joining Al Abut in his effort to learn Ruby and blog along the way.


Learning Ruby – Day 4

Day 4 – Iterators.

First, all chapters in programming books should start with quotes from Steve Martin .

Second, what’s a language without a convoluted loop syntax to geek out on? Geeez. I thought the purpose of learning to program was the same as learning Arabic from the Defense Language Institute – “because you can’t.” Ruby has iterators for logical, readable code? This means I might actually get something built rather than just debugging loops.

I’ve mentioned before how much I enjoy Slagell’s writing. I also like how the solutions to the exercises are listed immediately after the exercises. This isn’t typical, at in my collection of programming books. It makes getting un-stuck and getting the point much quicker.

Tip: Here’s how I’m remembering how the ‘step’ iterator works:

start.step(to, by)

an example to display all the odd numbers from 5 to -15

5.step(-15, -2)

Quite a few years back I was talking with a programmer/designer (in contrast to my designer/programmer) who didn’t like AppleScript because it was “too much like English”. With syntax like:

  • 3.times to do something, well, 3 times and
  • 10.downto(1) to count down from 10 to 1

I don’t think he’d like Ruby for the exact same reason – if not more so.


This post documents my journey through Sam’s Teach Yourself Ruby in 21 days. I’ll be joining Al Abut in his effort to learn Ruby and blog along the way.


PodSafeSound and the SpaceShots Rock

Tonight, listening to my “Getting Things Done” playlist while going through Day 4 of Ruby, the Spaceshots’ tune ‘I Promise the World’ came through the headphones.

I picked up that tune last November, while subscribed to BlogDigger’s mp3 feed (which I highly recommend for 2-3 days at a time). I search for ‘spaceshots’ at iTunes.

Did you mean “spaceshits”?

Umm. No.

Googling for them sends me to PodSafeSound.com – the independent resource for podsafe music. Yes, they have a feed and yes it includes the songs. That’s how to make my day.

Wait. It gets better. I head over to The Spaceshots site and they’re offering the entire album for download, free – in a single zipped file. Same goes for their side project, Alpha Pi.

These guys rock.