CMPT 383, or “Why I Hate Ted”

July 7th, 2009, 1:56 pm PDT by Greg

As many of you know, one of the goals for my study leave has been to prepare to teach CMPT 383, Comparative Programming Languages. The calendar says this course is:

Various concepts and principles underlying the design and use of modern programming languages are considered in the context of procedural, object-oriented, functional and logic programming languages. Topics include data and control structuring constructs, facilities for modularity and data abstraction, polymorphism, syntax, and formal semantics.

I took a similar course in my undergrad, and I think it was really useful in helping me see the broader picture of what programming is.

I have been thinking about the course off-and-on for more than a year. I had been forming a pretty solid picture of what the course I teach would look like and things were going well, despite never having devoted any specific time to it or really writing anything down.

Then I talked to Ted. Ted has taught the course before, and has thought a lot about it. His thoughts on the course differed from mine. In particular, he opined that “logic programming is dead, so why teach it?” (Okay, maybe that’s not a direct quote, but that’s what I heard.) So that leaves functional programming as the only new paradigm worth talking about.

He also convinced me that covering too many languages in the single course puts students into a situation of too many trees, not enough forest. (That is, they get lost in syntax and don’t appreciate the core differences between languages.)

Basically Ted did the most annoying thing in the world: he disagreed with me and he was right.

But, there is a lot of stuff that I hadn’t considered before, but might be worth talking about:

  • Type systems: static/dynamic, strong/weak, built-in data types, OO (or not), type inference, etc.
  • Execution/compilation environment: native code generation, JIT compilers, virtual machines, language translation (e.g. Alice → Java → execution), etc.

So, what the hell do I do with all of that? Any ideas how to put all of that together into a coherent course that students can actually enjoy?

Wikipedia-based Machine Translation

July 1st, 2009, 12:07 am PDT by Greg

I have been pondering this for a while and thought I might as well throw it in a blog entry…

Wikipedia is, of course, a massive collection of mostly-correct information. The information there isn’t fundamentally designed to be machine readable (unlike the semantic web stuff), but there are some structures that allow data to be extracted automatically. My favourite example is the {{coord}} template allowing the Wikipedia layer in Google Earth.

The part of Wikipedia pages that recently caught my eye is the “other languages” section on the left of every page. I’d be willing to bet that these interwiki links form the largest translation database that exists anywhere.

Take the entry for “Lithography” entry as a moderately-obscure example. On the left of that page, we can read off that the German word for lithography is “Lithografie”, the Urdu word is “سنگی طباعت”, and 34 others. Sure, some of the words might literally be “lithograph” or “photolithography”, but that’s not the worst thing ever. All of this can be mechanically discovered by parsing the wikitext.

Should it not be possible to do some good machine translation starting with that huge dictionary? Admittedly, I know approximately nothing about machine translation. I know there are still gobs of problems when it comes to grammar and ambiguity, but a good dictionary of word and phrase translations has to count for something. The “disambiguation” pages could probably help with the ambiguity problem too.

I’d guess that even this would produce a readable translation: (1) chunk source text into the longest possible page titles (e.g. look at “spontaneous combustion”, not “spontaneous” and “combustion” separately), (2) apply whatever grammar-translation rules you have lying around, (3) literally translate each chunk with the Wikipedia “other language” article titles, and (4) if there’s no “other language” title, fall back to any other algorithm.

I can’t believe this is a new idea, but a half-hearted search in Google and CiteSeer turned up nothing. Now it’s off my chest. Anybody who knows anything about machine translation should feel free to tell me why I’m wrong.

Trifle Recipe

June 10th, 2009, 4:09 pm PDT by Greg

The trifle that I regularly make is always a big hit. This is particularly joyous because it’s not very hard to make. The recipe is from the (annoyingly, out-of-print) New Canadian Basics cookbook, with a few mods by me. If you find a copy of Basics, buy it and live by it.

We served it at our open house and I posted a vague recipe then. Daniela wanted me to be more explicit, so…

Trifle

This makes a big party-sized bowl.

  • 2 pound cakes (or similar cakes from grocery store) cut into 1″ cubes
  • 1 C fruit coulis (recipe below)
  • 6 C fruit pieces (berries, peaches, mango,… whatever is available. Use canned/frozen if you must.)
  • 6 C custard sauce (recipe below)
  • 2 C whipping cream
  1. Make the other recipes below. They need to cool, so leave some time. (I usually do them the day before.) Eat a few handfuls of the cake pieces while you’re getting stuff together.
  2. For the first layers, use about a third of each: cake pieces, fruit coulis, fruit pieces, custard.
  3. For the next layers, repeat step 1 twice more, using the rest of each ingredient. Cover and refrigerate for 4–8 hours.
  4. Whip cream and spread on top. Garnish with some berries.

Fruit Coulis

This makes more than the trifle needs, but there’s nothing wrong with having some berry sauce in the fridge. Reasonable substitution: decent berry jam thinned with a little fruit juice or sherry.

  • 1 kg bag of frozen fruit (mixed fruit or mixed berries)
  • water
  • sugar
  • cornstarch
  • 1/4 C sherry (optional)
  1. Put 1/4 C of water and 1 tbsp of cornstarch in a jar/tupperware. Shake to combine. (Goal: no cornstarch lumps.)
  2. Combine 1/4 C water, 1/4 C sugar, and the berries in a saucepan. Cook over medium heat, stirring occasionally.
  3. When the berries have started to cook, add half of the cornstarch mixture and stir. Make sure the mixture boils to cook the cornstarch.
  4. Look and taste. Add more cornstarch mixture if it needs to be thicker; sugar to taste; cook longer if there are too many berry chunks.
  5. Turn off heat and stir in sherry.

Custard Sauce

Makes about 6 cups. You could probably substitute 6 cups of custard made with a custard powder, but I have never tried.

  • 3/4 C sugar
  • 6 tbsp (=3/8 C) cornstarch
  • 4 1/2 C milk
  • 6 eggs
  • 1 tbsp vanilla
  1. In a big microwavable bowl, combine the sugar, cornstarch, and milk. Whisk to combine.
  2. Microwave on high for 3 minutes. Whisk to combine and break up any lumps. Repeat until it thickens. (It will boil a bit: covering the bowl saves cleanup.)
  3. In a smaller bowl, beat the eggs. Whisk in a little of the hot mixture. (You’re preventing egg lumps here: add hot mixture to eggs slowly while whisking, until you have added about as much mixture as you had eggs originally.)
  4. Microwave for a few more minutes. Stop and whisk every minute or so. Continue until the whole thing has cooked (thickened and maybe boiled a bit).
  5. Add the vanilla.

Alaska – Kat’s perspective

June 2nd, 2009, 11:43 am PDT by Kat

By the sounds of Greg’s post, the cruise was a downer. Contrary to Scrougy-McScrougerson’s account, we had a fun (and relaxing) time.

During the week we saw a wolf (dark brown and kind of mangy. Just realized that this wolf was probably shedding it’s winter coat – hence it’s mangy look), a bear, a martin (Greg’s mom saw it at the dock at Juneau), black-legged kittiwakes and other gulls, pupping and diving harbour seals, and a pod of orca.

Holland America has what they call “dam dollars”. They’re pretty much play money that you earn by participating in ship activities. Other cruise lines have similar things like Royal Caribbean’s “Ship-Shape dollars”. Anyways, all week I dragged Greg to team trivia ($1 each for participation), name that tune ($3 each), Wii bowling ($1 each + $3/spare and $5/strike), and the most profitable, polar bear swim ($10 each! + a nice certificate!). In the end we’ve ended up with 59 dam dollars! We got a hat for Greg’s dad and two mugs for us and gave the rest of our dollars to a boy that was at all of the activities. While I did have to “drag” Greg to these events, he did have fun while we were there, honest!

After playing team trivia almost every day (and doing fairly mediocre at it the whole week) we finally won on the last day, and we weren’t even there to see the victory. We teamed up with a couple from Burnaby and another couple from Vancouver Island, and ended up in a quadruple tie at the end of what was possibly the toughest game during the week. We initially thought it was a 3-way tie not involving our team, so Greg and I left for our 5:30 dinner seating. However, after we left, our team found out that due to a miscalculation, it was actually a 4-way tie. The rest of the team won during the tie-breaker and our entire team won Holland America picture frames, which were the nicest trivia prize of the week. The two guys actually came and found us in the dining room and presented us with our frames! Yippee!! 😀

The views of the Margerie Glacier in Glacier Bay National Park were really stunning. If you’re ever in Skagway, I recommend the Skagway Brewing Company beer tasting which comes with a free hat! 🙂

Alaska Summary

June 1st, 2009, 11:43 pm PDT by Greg

We’re back from the Alaska cruise. We didn’t blog daily like China since it was a lot more sedate. Here’s the rundown:

I put pictures of the cruise up if you want to see it. There’s some good stuff in there. Again, many of the pictures are geotagged, so you can click the Google Earth/Maps link on the left of the gallery.

I wasn’t expecting wild excitement on an Alaska cruise with Holland America (which has an older demographic). But, I was looking forward to the downtime and being bored, so that was just fine with me.

That kind of worked out, but I spent a lot of time being dragged around by Kat to events on the boat. Kat decided to collect ship bucks that could later be redeemed for swag. That meant participating in (for example) several Name-That-Tune games which consisted entirely of music for the Holland America demographic which we didn’t know.

The shore days were a little depressing. The three cities we went to seemed to only exist for the purpose of providing cruise ships somewhere to dock and their passengers to buy crappy souvenirs. (That’s probably not entirely true, but from what a cruise ship passenger sees, that’s what it looks like.) Ketchikan was my favourite: it felt the least artificial.

That’s not much of a summary of a week of travel, but short of describing every day in excruciating detail, I’m going to stop. Kat probably has more highlights that she can blog about all by herself.

imapsync migration

May 21st, 2009, 5:29 pm PDT by Greg

A quick technical note… I just want to get this down so it’s findable later.

I was trying to move my mail from FASnet to the new Zimbra server. The Zimbra wiki suggests imapsync to migrate mail from one IMAP server to another.

When I tried that, imapsync insists on spidering every folder on the source server to see what’s there. Since FASnet is set up in its own particular fashion, that means it will look through every file in my home directory. That’s a lot of load on the IMAP server and something that caused the system admins to ask me nicely to stop.

To prevent the spidering, I replaced this line in the imapsync script:

my @all_source_folders = sort $from->folders();

with this:

my @all_source_folders = ();

As long as you specify a --folderrec (or --folder or --subscribed) and no --include, it will still work just fine. My command line was:

./imapsync --host1 imap.css.sfu.ca --user1 ggbaker --host2 imapserver.sfu.ca --user2 ggbaker --noauthmd5 --folderrec mail --exclude old --prefix1 mail --prefix2 fasnet 2>&1 | tee log

Everything seemed to work, and it looks like I have my email moved over. The line in the imapsync summary “Total bytes skipped: 36444” worries me a little. I wonder what those bytes were.

Alaska-bound

May 19th, 2009, 9:46 pm PDT by Greg

Having comfortably adjusted to pacific time, Kat and I are headed out again. This time is much more low key: we leave for an Alaska cruise on Saturday.

My parents came along with this idea some time last year. They have done the Alaska cruise before and wanted to take us with them. Fine by me.

I guess I don’t have much to say about the cruise other than “we’re going”. With the China trip two three weeks ago, I haven’t had much mindshare for the cruise. Plus, there isn’t much to plan: get on the boat and figure it out from there.

I’m planning to rent a 70–200mm lens for the cruise (since I don’t have a decent long lens). That should keep me occupied for a while, and get some nice pictures of the glaciers, etc. That was lens #2 on my recent Lens Wish List. I already bought lens #1, the 4.5mm fisheye. This is my attempt to stop myself from actually buying the zoom: I can play and get it out of my system.

Geotagging

May 15th, 2009, 1:28 pm PDT by Greg

Astute observers (or people I told about it) will have noticed that in our gallery of China pictures, clicking the links on the left “View Album on a Map” and “View in Google Earth” do cool stuff.

I promised I would write about how I did that, so I will. There are obviously other ways to geotag photos, but this is what I did.

The Gear

Before the trip, I had the realization that I didn’t have to get some kind of GPS receiver that connected to my camera: any GPS data was enough, as long as it was timestamped. The photos I take are timestamped, so if the GPS data is too, I can connect the two and figure out where pictures were taken (assuming the GPS and camera are close to each other).

So, before the trip, I picked up a eTrex Venture HC. It claimed to be high-sensitivity, so that sounded good. Also, it was on the cheaper side of GPS receivers and it records the track data I needed.

I had the GPS on a lot over the trip, and I think I ran through 4 pairs of AA batteries the whole time. That’s quite reasonable to my mind.

The cameras were my Rebel XT and Kat’s SD800. Basically, it can be any Digital camera with its clock set reasonably accurately.

On the Trip

When we were about to arrive somewhere, all I had to do was flip on the GPS and throw it back in my camera bag. Then, take some pictures. When leaving, turn the GPS off.

The GPS records its position (“tracks”) until I turn it off. (It’s important with a Garmin GPS to not “save” the track: that throws away critical time info.) Just turn it off when done.

Processing

The data can be pulled off the GPS to a GPX file with its own software or GPSBabel. Photos come off the camera in the usual fashion.

I couldn’t find anything I liked to get the GPS data and the camera time stamps together, so I did what I always do in these situations: I started writing Python. The job was basically to read the GPS data, read the timestamps from JPEG files, interpolate the GPS data, and write the position data back to the JPEG.

I threw what I have on SourceForge as “Geotag Merge“. I haven’t “released” it yet, so you have to grab the Subversion repository if you want to play. Sooner or later, I’ll find some best-practices for packaging Python-based applications and I’ll do a beta release.

I added the Gallery2 GPS module to my gallery to make it all work.

An Example?

Okay, look at this picture which, according to its time stamp, was taken at 2009-04-19 14:20:08 (Beijing time) = 2009-04-19 06:20:08 UTC. Looking in the GPX file extracted from the GPS, I see these entries:

<trkpt lat="40.360190626" lon="116.013850048">
  <ele>829.274414</ele>
  <time>2009-04-19T06:19:48Z</time>
</trkpt>
<trkpt lat="40.360201774" lon="116.013833955">
  <ele>829.274414</ele>
  <time>2009-04-19T06:20:11Z</time>
</trkpt>

Like all good XML, this is minimally-human-readable: two observations separated by 23 seconds, with latitude, longitude, time, and elevation.

So, I deduce that the picture was taken in between these locations (and in fact very close to the second). A quick linear interpolation, and we decide that the picture was taken at 40°21’36.72″N 116°0’49.81″E (and 829.27 metres above sea level). This is then written back as part of the image’s EXIF tag, and it can be picked up by any geotagging-aware photo viewer.

Pictures!

May 2nd, 2009, 6:13 pm PDT by Greg

We have posted pictures from our trip! They are organized by city, which seemed to make the most sense to me.

Note that they are (almost) all geotagged, so you can click the left-side links “View Album on a Map” or “View in Google Earth” on the album (or any subalbum) to see the pictures geographically. This was done with a handheld GPS and some cleverness. The tags seem to generally be within about a few metres of the true location where the photo was taken.

I’ll explain all of the geotagging stuff in a later blog post.

Edit: By the way, I rolled over the odometer on my Rebel XT on the trip: I took img_9999.jpg, then img_0001.jpg in the mini-three gorges. Ten thousand pictures on that camera over its lifetime. It now officially owes me nothing.

We’re back!

May 1st, 2009, 8:35 am PDT by Greg

We got back to Vancouver yesterday afternoon, safe and sound. That is all.

I temporarily blocked access to our “china” gallery while we get the photos up. Don’t want anybody getting an incomplete experience. 🙂

« Previous Entries   Next Entries »