Thomas’ Tales: Walt Disney World, Day One

Note: Today’s post was written by my son, Thomas. He’s eleven and very excited that we are at Walt Disney World. I edited his post, but the text is his.

Hello. I, the blog famous Thomas, will be writing every day until Monday about our trip to the almost as famous as me, Disney World. Now to get started, we rode down here yesterday and unpacked, but that was twenty-four hours ago, so let’s just forget that. Today, we woke up early to see the Magic Kingdom opening show/song , and it was good. After that, we went to Tomorrowland, where we blasted aliens and moved people, and sent my parents into a mountain in space. Then we headed over to Adventureland, where we went to see the tiki birds and rode on boats. One boat ride being a simple tour of the wildlife and the back-side of water (which was amazing), on the other we went through a pirate-infested town that was currently on fire. I don’t know why it was on fire; maybe someone dropped a lantern or something.

Now for the interesting part. When we were on the People Mover,  I couldn’t believe what happened. As we were entering the part where it goes through Space Mountain, the ride came to a non-screeching halt. I don’t know why, but it took FOREVER to get it going again. Luckily, there were no more problems with our visit; so far, that is. Now we are in our room, relaxing.

That’s all, folks, but expect more from me tomorrow, and the next day, and the next day, and so forth.

WCBHM10 & Birmingham’s New Railroad Park

For the third year in a row, I attended WordCamp Birmingham. And for the third year in a row, it’s delivered on great content. My favorite session was one that I almost passed on; Sara Cannon‘s “Beyond the System Font: Advanced Web Typography” sounded like the same talk she delivered last year, but the technology has leaped forward in the past year, so the session was totally new. I will be implementing typekit.com on this blog, very soon. Thanks, Sara.

Yesterday, we were meeting outside at Birmingham’s newest urban project called Railroad Park. It’s a very nice greenspace right in the middle of town, with spacious covered pavilions that we used for shelter from the really hot sun. I walked around the park before heading back to Georgia and took a bunch of photos, the best of which are below.

[ichc-flickr-slide width=”480″ height=”385″ username=”joeygibson” set_id=”72157624995821638″ player_r=”71649″]

99 Scala Problems #28 – I Like My Solution Better

I’ve been working through this list of 99 Scala Problems, which is modeled after this list of 99 Prolog Problems. As I’ve been going through them, I have been comparing my solutions to those provided (obviously). Sometimes, my solution is more or less the same as the “official” solution. Sometimes, theirs is better. In the case of problem 28, I think mine is far easier to read and understand.

Problem 28 has two parts. The first part reads:

a) We suppose that a list contains elements that are lists themselves. The objective is to sort the elements of the list according to their length. E.g. short lists first, longer lists later, or vice versa.

Running the function should look like this:

[scala]
scala> lsort(List(List("a", "b", "c"), List("d", "e"), List("f", "g", "h"), List("d", "e"), List("i", "j", "k", "l"), List("m", "n"), List("o")))

res0: List[List[java.lang.String]] = List(List(o), List(d, e), List(d, e), List(m, n), List(a, b, c), List(f, g, h), List(i, j, k, l))
[/scala]

For this part, my solution was almost identical. Here’s what I came up with:

[scala]
def lsort[T](ls: List[List[T]]) = {
ls.sortWith {(a, b) => a.length < b.length}
}
[/scala]

You can see that this function takes a List of type T, and then calls the sortWith method on that list, passing in a function value that sorts the lists based on their length, shortest to longest. The “official” solution was only slightly different:

[scala]
def lsort[A](ls: List[List[A]]): List[List[A]] =
ls sort { _.length < _.length }
[/scala]

Here, they used A instead of T, but that doesn’t affect anything, and they specified the return type, while I left mine inferred. Instead of assigning each bucket of the list to a named variable, as I did, they use the underscore placeholder. The two functions are functionally (get it?) identical, but theirs is a bit shorter because they removed the outer braces, and were able to skip the parameter list, since they used the underscores.

Now, the second part is where I diverge from the official solution. Here’s the problem description:

b) Again, we suppose that a list contains elements that are lists themselves. But this time the objective is to sort the elements according to their length frequency; i.e. in the default, sorting is done ascendingly, lists with rare lengths are placed [first], others with a more frequent length come later.

And the expected call and result is

[scala]
scala> lsortFreq(List(List("a", "b", "c"), List("d", "e"), List("f", "g", "h"), List("d", "e"), List("i", "j", "k", "l"), List("m", "n"), List("o")))

res1: List[List[java.lang.String]] = List(List(i, j, k, l), List(o), List(a, b, c), List(f, g, h), List(d, e), List(d, e), List(m, n))[/scala]

First, let’s look at what they presented as the solution. It referenced functions from other files, but I have included them all here for easy of viewing.

[scala]
def lsortFreq[A](ls: List[List[A]]): List[List[A]] = {
val freqs = Map(encode(ls map { _.length } sort { _ < _ }) map { _.swap }:_*)
ls sort { (e1, e2) => freqs(e1.length) < freqs(e2.length) }
}

def encode[T](ls: List[T]): List[(Int, T)] = {
val packedList = pack(ls)
packedList map {list => (list.length, list.head)}
}

def pack[T](ls: List[T]): List[List[T]] = ls match {
case Nil => Nil
case h :: tail => (h :: tail.takeWhile(_ == h)) :: pack(tail.dropWhile(_ == h))
}
[/scala]

I think this is very confusing code. It’s calling the encode function which does run-length encoding of the passed-in thing. It then uses a Map of these encodings to sort the passed-in list. The presence of five underscores in the first line, obscures where those parameters are coming from, and the final underscore is actually part of the _* method of the Array class!

My solution, while being a longer function, is far more readable, in my opinion. And, it’s the same number of lines as the three-method solution. Here it is

[scala]
def lsortFreq[T](ls: List[List[T]]) = {
val lengthMap = scala.collection.mutable.Map[Int, Int]()

for (l <- ls) {
val len = l.length
if (!lengthMap.contains(len)) {
lengthMap(len) = 1
} else {
lengthMap(len) += 1
}
}

ls sortWith {(a, b) => lengthMap(a.length) < lengthMap(b.length)}
}
[/scala]

In my function, I created a mutable Map and then iterate over the list, getting each item’s length, and then keep a running tally of how many items had that length. The map has these lengths as its keys, and the number of items with that length as its values. Get it? I then sort the original list by having each item in the comparison lookup how many items share its length, and use that as the sort criterion.

I have no idea which of these solutions is more efficient. For small problems like this, I doubt there’s any measurable difference. But I do believe that my solution is easier to read and understand. So much so, in fact, that I think someone who is not familiar with Scala would be able to easily figure out what it’s doing. I don’t know that the same can be said of the other solution.

I got criticized for promoting terse code in this article, so this is my attempt at balance. 🙂

Note: I did change the inputs to these functions from symbols to strings. The code formatter I use on the blog wasn’t colorizing things properly when there were symbols involved.

Two Videos From Lula Lake

As I said earlier today, my buddy Tim and I went hiking on Saturday and ended up spending much time at Lula Lake. You can see pictures from that excursion in the previous entry. (The first of the pictures are from Cloudland Canyon. The pics from Lula Lake begin with the rocks in the river that actually contained water.) Below are two videos of the beauty at Lula Lake. The first I took standing directly next to the cliff edge at the top of the falls. The second was taken from across the lake, looking at the falls and the surrounding cliff. If that place were on my property, I don’t think you could pry me away.

Hiking Cloudland Canyon and Lula Lake

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

My buddy Tim and I went hiking this past Saturday. We went to Cloudland Canyon, which is up in North Georgia, near Chattanooga. We spent about 2.5 hours there, scaling the 600 step staircase, looking at the almost-completely-dry waterfalls and the nearly-devoid-of-water creeks and looking for the I-know-it’s-here-somewhere-dangit geocache, placed there by the GA parks service. We never found the cache, but vowed to return when there is water around, since one of the clues to finding it depended on there being water. Doesn’t everything?

After the hike there, which was beautiful and fun, don’t get me wrong, we inquired of Ranger Amy if there were any falls nearby that had, you know, some water in them. She told of us about one that wasn’t too far, but then she said, “Wait, maybe Lula Lake. It’s beautiful, but they aren’t open all the time. Let me call them for you.” A few minutes later, she told us that they were open, and we definitely needed to go. She gave us a map (which we quickly discovered was not to scale), drew “about where” it was on this map, and wished us good luck. We got back into my car, and headed out.

After about 45 minutes of “wast that the turn?” and “do you think we just missed it?” we finally found the proper turnings, and ultimately made it to the entrance. If you were not looking for it, you would have missed it. If you were looking for it, you still could have missed it, since there was nothing but hand-written paper signs, peeling and twisting with the sun and heat.

Anyway, we drove down the somewhat perilous (for a car) drive and found that we were not alone in our quest. There were probably 50 or more cars in the parking area. It’s free to be there, but they ask for donations, since it’s a private land trust. They gave us a map, told us the easiest way to get to the lake and falls and sent us on our way.

I should pause here to relate our Big Mistake™ for the day. Ranger Amy had told us that getting to the falls at Lula Lake was “easy” and would probably only take “ten or fifteen minutes.” Thus, as we got out of my car, we both decided to leave our water packs in the trunk. Please keep that in the back of your mind as you read on. Tim also decided to leave his trekking pole, but I took mine. Now, let’s continue.

We started out walking down the gravel road, but when hiking, “paved” roads sort of seem like cheating to me, so we took the first trail off the road we found, the “Ford Trail,” which began with fording a stream. It was easy, and nobody got wet. We then started following this trail, which essentially paralleled the river. It did not parallel the river in terms of altitude, going up and down, over and over. This trail ultimately rejoined the paved road at a bridge, just above the falls. We walked to the very precipice of the falls and looked over. Wow. What a view. We were standing at the edge of a cliff, about thirty feet above one of the most beautiful lakes I’ve ever seen. It had stunningly green water and was surrounded on one side by a bowl-shaped cliff. The water looked deep at the bottom of the falls, and it was just begging us to jump in. We did not.

We then got back to the paved road and walked a little farther so we could get to the lake proper. This place was gorgeous. I wanted to swim, but I didn’t have trunks, there were other people around and there were big signs saying swimmers would be prosecuted. All three conspired to keep me from swimming.

Farther down the paved road was the second falls. We were’t able to get very close to this one, but it was at least one hundred feed tall. There wasn’t a whole lot of water going over it, but the sound it make when hitting the bottom was impressive. I wish we could have gotten closer, but neither of us could see how we could. We did see some people at the very bottom of this falls, but the trail we found that went down was really steep, and neither of us wanted to have to come back up that way, so we took a pass.

A short way farther down the paved road, we came to the end of the property and a slightly trail-like spur off to the right. Tim checked the map and based on the topo lines, it looks like it would be pretty steep in places. We decided to double back a ways to the “somewhat more gentle” trail we had seen that would still get us to the top of the ridge, just “more gently.” But as we started to leave the spur behind, my curiosity got the best of me and I said, “You know, I’m probably going to regret this, but I sort of want to know what this trail is like.” (Or something close to that. The next hour is a bit fuzzy at times.) So we headed on to the slightly trail-like spur.

Within just a few minutes, the trail got steeper and I started huffing and puffing as my legs began to complain loudly to me about what I was asking them to do. I continued on, with Tim about ten feet or so ahead of me. At one point, I looked back to where we had come from and saw that we had already ascended quite a bit, and that I really didn’t want to try to go back down that way. The only way for us to go, realistically, was up. And so we continued.

Another twenty minutes or so later we came to the “So, You Think You’re A Man” stage of the ascent. I like to call this section the, “How the F@#k Am I Supposed To Get Up There‽” section of the trail. The land owners had generously hung sturdy ropes with knots in them to assist you in your climb (yes, climb, this was no longer a hike), and we used these ropes to good use. Tim made it up first, of course, and after I made it up the second of three ropes, I tossed him my pole, because it was a hindrance at this point. I pulled myself up the final rope, cursing and spitting all the way. Now, I should mention that the trail leading up to this had been getting more and more narrow, with drops of twenty to thirty feet should you misstep. And this bit with the ropes was just crazy. My point is that we were facing a bit of actual danger, and I don’t know that either of us realized it until we were mostly through it.

Once past the ropes, we assumed that we were at the top, and there wouldn’t be any more vertical to worry about. We were wrong, but it wasn’t horrible. I was still thankful when we finally did make it to the top, and the trail got nice and flat. Up on top, there was a field, and some pik-nik tables. We spoke with some nice folks who had taken the sensible route up, and warned some others who were heading in the direction from which we came about the steepness of what they were heading toward. They all seemed grateful. The views of the valley below from way up here were lovely, and I took several photos.

But what I really, really, wanted was some water. Of course, since we were both dumb-asses, we had left it in the car. Remember the Big Mistake™? So I debated on whether or not it would be considered gauche to ask some other hiker for a sip of the water that they so smartly brought with them. I didn’t ask the nice couple up top, nor did I ask the next two or three people we saw. But finally, I saw a guy with a huge bottle of water that was clearly frozen in the middle. That meant ice cold water, which would feel so good. We greeted him, and then I said something like, “Excuse me um you see we didn’t think we were going to be out here so long and so we left our water in the car and I hate to ask and everything but if you could would you mind terribly much if I could have just a small swig of your water please?” He smiled and handed me the bottle. I wanted to wrap my lips around the bottle and drain every non-frozen drop (like Homer when Moe told him the beer taps had run dry), but I restrained myself and just poured a bit into the palm of my left hand. As I expected this water was the absolute best water I had ever tasted. It was cold and refreshing, and just that small amount was enough to revive me. And to keep my lips from sticking to my teeth, which had been impairing conversation.

We walked about a mile on the top of the ridge, and then started our descent. This was not terribly steep, but after a while, my legs began complaining again. I just ignored them. We were heading back down and that’s all that mattered. We finally made it back to the parking area, and went to task the people in the tent about the lake. It’s a natural lake, which is why the water doesn’t look like chocolate milk as most Georgia lakes do, and is around thirty to forty feet deep. In case you were wondering. He also said the dark discoloration on the rock was from where they used to wash coal there, since the whole area used to be a coal mine.

We ended up spending about 3.5 hours at Lula Lake, longer than we spent at Cloudland Canyon, and we had water then!

So, to sum up. Cloudland Canyon is beautiful, but it really needs moving water. Ranger Amy said March is quite nice. Lula Lake is sublimely beautiful and I would recommend it to anyone who likes to look at natural beauty. If you stay on the paved road, it really would be about a fifteen minute walk from the parking area.

And remember this: if you have a water bottle/water pack, take it with you, even if you think you’re only going to be there for a short while. You will thank me for this later. Trust me.

Let Them Build The Mosque

Unless you are living under a rock, you have heard the controversy surrounding the “ground zero mosque.” Essentially, a group of Muslims want to build an “Islamic community center,” that will house a mosque, two blocks away from the former World Trade Center. This has sparked a firestorm of protest from the right, claiming it is everything from insensitive to the next terrorist attack itself. This has annoyed me greatly.

One of the founding principles of this country was religious freedom. This means that you can support any religion you want, or no religion, and not be molested by the government. Increasingly, those on the right construe this as, “You can be any religion you want, as long as it’s Christian.” If you are a Buddhist, a Hindu or, (God forbid!) a Muslim, (I’m not sure if they consider atheists better or worse than Muslims), then your rights and desires are not relevant. This is a clear case of religious freedom: these people want to built a house or worship, on private property, using private funds. There is no compelling reason why they should not be allowed to do it. Unless you believe that all Muslims are terrorists.

And that’s exactly what most of the commentators on the right seem to think. Listen to the statements of Newt Gingrich, that moron Sarah Palin, or any of the talking heads on Fox News. They are all screaming about how “it just isn’t right” to build this Mosque “at ground zero” where so many lost their lives. Yes, 3,000 people did lose their lives at the WTC site, and yes, the attack was carried out by Muslim extremists, but that does not mean that all Muslims are terrorists.

Now, if you were to search my blog, you would probably find some inflammatory statements made by me about Muslims. Statements that might indicate that I considered all Muslims to be terrorists. I wish to publicly repudiate those statements right now. (Or “refudiate” them, as the learned Sarah Palin would say.) I’m not making excuses for my former statements, (well, maybe I am…) but I don’t think I was thinking about the situation rationally. I was caught up in a patriotic ferver, that I now see was incorrect. I’ll say it again: not all Muslims are terrorists.

In fact, a very small minority of them are terrorists, or support the actions of terrorists.

“But wait,” you say, “the Koran is ‘full of violence’ and commands by their ‘god’ to kill the unbelievers.” Indeed. May I then direct you to your bible to that part called the “old testament.” That’s the part that lots of Christians seem to forget about. There’s more violence in there than you can shake a stick at. Does that make us a violent religion? No. See what I’m getting at?

“But wait,” you say again, “those Muslims want to spred Islam all over the world! They want everyone to be a Muslim.” Indeed. Now, may I direct you to your bible, to Matthew 28: 19-20, which reads: “Go therefore and make disciples of all nations, baptizing them in the name of the Father and of the Son and of the Holy Spirit, teaching them to observe all that I have commanded you. And behold, I am with you always, to the end of the age.”

What this all comes down to is a bunch of Christians who are scared of Islam and don’t like to see it spreading. Despite their claims of “But I have a Muslim friend!” or “I don’t care if they build another Mosque, just build it somewhere else!” or “I don’t have a problem with them building it, but building it there is just insensitive!” it all amounts to the same thing. They don’t like Muslims, and they want them to go away.

I think they should be allowed to build it. I think the protesters are wrong, but I support their right to protest and make their opinions known, as long as they remain non-violent. That is my main concern. I wonder how long it will take, after construction begins, before the site is vandalized (or worse) by those who oppose it. “But that wouldn’t be very Christian!” you say. Indeed, it would not.

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.