# A-Hiking I Did Go

Yesterday I played hooky from church, and my buddy Tim and I headed up to the North Georgia mountains for a bit o’ hiking. Tim’s been doing this a lot, but this was my first time, and it was great fun. We hiked Raven Cliff Falls, which was a five mile round-trip, then had some lunch, and then stopped by Tallulah Gorge State Park. I was completely bushed by this time, so we just walked to the easy-to-get-to overlooks, and then called it a day. I had so much fun, I’m ready to do it again. ðŸ™‚

Here are a few of the better pictures I took during the day.

[ichc-flickr-slide width=”500″ height=”375″ username=”joeygibson” set_id=”72157624251161793″ player_r=”71649″]

# Procedural vs. Functional

With the rise of Scala and Clojure, there’s been a lot of talk lately about procedural vs. functional styles of coding. Most developers are accustomed to procedural coding, and functional can be hard to get a handle on. I was working through Programming in Scala (again) this morning, and I came upon this function:

```// Procedural implementation
def longestWord(words: Array[String]) = {
var word = words(0)
var idx = 0

for (i <- 1 until words.length)
if (words(i).length > word.length) {
word = words(i)
idx = i
}

(word, idx)
}
```

The purpose of this function is to find the longest word in the passed-in array, and return a tuple with that longest word, and its index in the array. You can see that in this function, we have two vars, one for the current longest word, and another for its index in the array. We then use a for expression to walk the array, reassigning word and idx when we find a longer word. This is very much like how you would write this in Java.

I decided to rewrite this function in a more functional style, just to see how my functional chops are coming along. Here’s what I ended up with:

```// A more functional implementation
def longestWord(words: Array[String]) =
(("", -1) /: words.zipWithIndex) {(old, cur) =>
if (cur._1.length > old._1.length) cur
else old
}
```

First of all, notice how much shorter this function is than the first one. Also, notice that there is only a single expression in the function, so the outer curly braces aren’t necessary. What this expression is doing is calling zipWithIndex on the passed-in array, which results in an array of tuples containing each word and its index. We then call foldLeft using its operator name of /:, with its initial argument being a tuple with an empty string and -1 for an index. What foldLeft does is apply the function value passed to it to pairs of arguments. On the first pass, the arguments are what was passed in and the first element in the array. On the second iteration, the arguments are the result of the first pass and the second element in the array. This then continues through the entire array. What is returned after the final pass will be a tuple that contains the longest word in the array, and its index.

Now, I don’t claim to be a functional master or anything, but I think this is a decent illustration of how the functional style can reduce the lines of code, and the number of mutable variables, while making the code easier to read and understand.

# My New Ford Focus

Last Thursday, on the way home from the office, I got on I-285 and quickly merged over five lanes to the left. I then realized that my accelerator was no longer making the car go faster. Fortunately I was on a long, downhill slope, and I had some built-up momentum, so I didn’t get stuck. I then coasted over six lanes to get to the righthand shoulder. Once there, I turned the car off, then back on. To my surprise, the tachometer jumped up, as it should have, when I pressed the gas pedal. I was able to drive the remaining 28 miles home without incident. But I knew there was probably something wrong with the transmission, based on how hard it was shifting.

The next day, I took it to my usual shop, and after checking it out, they told me that there was something wrong with the transmission, but they could not fix it. Since Saturn is no longer in business, parts are already getting scarce. I had already decided that unless the needed repairs were extremely cheap, I wasn’t going to sink any more money into it. This settled it.

On Saturday, we test drove and bought a new 2010 Ford Focus. It’s a very pretty red. I really wanted a blue one, but none of the six dealerships anywhere near us had an SEL model in blue. But once I saw the red, I liked it enough to get it. So far, I like it. It comes with the SYNC system, which is nice, but not without its quirks and problems. The car is peppy (for a 4 cylinder), drives smoothly and is very quiet in the cabin, even at high speed. Every time I drive it, it grows on me a bit more.

If you’re interested, here are some photos of it.

[ichc-flickr-slide width=”500″ height=”375″ username=”joeygibson” set_id=”72157624125318785″ player_r=”71649″]

# It’s Three Tigers, Not Two Bulls

On our recent trip to Myrtle Beach, we ate at the Planet Hollywood our first night there. Apart from the fact that they were out of Key Lime Pie and bananas for the Bananas Foster Cheesecake, the meal was fine. Thomas and I walked around, looking at all the various movie props, but there was a gigantic battleship that was hanging from the ceiling that I could not figure out. I decided to ask the hostess if she knew. This is what transpired when I approached the hostess stand and asked her.

Me: “Hi. Um… what movie was that battleship from?”
Her: “Oh, that’s from a movie called ‘Toro, Toro.'”
Me: “What movie?”
Her: “‘Toro, Toro.'”

I then realized that she actually meant “Tora! Tora! Tora!” which is a WWII movie about the Japanese attack on Pearl Harbor. I was able to stifle my laugh, so I didn’t make her feel bad, but when I got back to the table, I had a good laugh with the family.

There are two reasons why this is funny. First, “Toro” is the Spanish word for “bull.” “Tora” is the Japanese word for “tiger,” which was used as a code word for “attack” when they bombed Pearl Harbor. Second, the way she said “Toro, Toro,” was funny. She said it with both authority and a very Southern accent that worked together to really tickle me, almost to the point of laughing in her presence, which would have been bad/mean.