Inappropriate sarcasm

Dear modern C++. It’s okay. We like you. You don’t have to pretend you’re something you’re not.

Herb Sutter just gave an excellent talk on modern C++, but I thought one part was more than a little silly. At about the 10 minute mark, he showed an example (originally due to Bjarne Stroustrup) calculating the mean in Python and C++14. Before revealing the code, he sarcastically said that maybe he didn’t leave enough space on the right hand side because it will be so much longer and harder in C++. Then we see that the C++14 is line-for-line the same as how you would write it in Python. Har har.

screen cap of Python and C++14 side by side

The thing is, that isn’t how you would write it in Python. If you weren’t Bjarne Stroustrup, you would write

def mean(seq):
    return sum(seq)/len(seq)

Heck, if you’re using Python 3.4, you would just write

from statistics import mean

Showing that C++ is every bit as expressive as non-idiomatic Python doesn’t really show anything.

In Appreciation of Jazz

jeff_hellmer1.png

Figure 1: Jazz Appreciation

I just completed the Jazz Appreciation MOOC at edX. It was fantastic! It’s like a whole new world has opened up for me!

I am a lifelong fan of rock and roll, so I wasn’t completely unaware of jazz. I’ve been to a Pat Metheny concert. I own a Miles Davis record. Rock and roll is a term which includes an awful lot of things. The intersection of rock and roll and jazz is not exactly empty (both include blues, for example).

But I knew there was a whole lot more to jazz that I didn’t get. Jazz made me feel stupid (“I mean, just play the right notes!”) and jazz fans have a (mostly deserved?) reputation for snobbery. So jazz had remained largely inaccessible to me. I didn’t get it and there seemed to be no good way to find out what others were getting.

Until now.

Jeff Hellmer and the folks at the University of Texas (that’s right, UT. In Austin. The indie rock mecca. Who knew they even had jazz there?) have made remarkably effective use of the MOOC platform to spread their encyclopedic knowledge and obvious love of jazz to anyone in the world who wants it. And it’s completely accessible. Hellmer is whatever the opposite of a snob is, generously sharing his vast knowledge without making anyone feel dumb. Ten weeks ago I knew hardly anything about jazz, really. Now, I’m so excited, I have to be careful that I don’t turn every conversation into a one-sided jazz lecture. It’s an amazing transformation!

And an it’s an amazing gift. Of course I haven’t learned everything. Not by a long shot. Jazz is a huge topic. But I feel that I now have the tools I need to explore on my own. I didn’t have that ten weeks ago. It’s much more than just listening and deciding if you like it or not. I can now listen and identify all sorts of things about a piece. I still might not like it, but now I know why.

This is the third MOOC I’ve taken. Last year, I took the Stanford database course and MongoDB for Developers. Both of those consisted of video lectures and programming assignments. Jazz Appreciation also had video lectures, but in lieu of programming assignments they used something called Cerego, which was sort of like flashcards, only multimedia. In addition to text, they could play music to quiz you with. Also, the questions weren’t just random; they used an algorithm to decide what you still needed to work on. It was kind of fun, if a bit repetitive. Some of the questions were subverted by the pictures. For example, one of the little icons for “Fusion” was a picture of Herbie Hancock. So if it was a question about Herbie Hancock and you already know what Herbie Hancock looks like, then you don’t really have to know the answer to the question. The task is reduced to “click on the picture of Herbie Hancock.”

cerego1.png

Figure 2: Click on the picture of Herbie Hancock

Another difference with the previous MOOCs I’ve taken were the video lectures. Rather than speaking to slides or a white board, Hellmer lectured right from the piano. This enabled him to illustrate many points immediately on the keyboard.

jeff_hellmer3.png

Figure 3: Motivic Development

There are also other members of the UT faculty with different instruments in some of the videos. Most of the videos are just Hellmer at the piano, though. He’s very skilled and managed to get his point across even when he was talking about things that pianos can’t really do, such as scooping or growling.

Like the other MOOCs I’ve taken, this one had a discussion board. I don’t think this format scales up to thousands of users, but there were some nice discussions on there with interesting people from all over the world. I learned about Oscar Peterson, whose statue in Ottawa I have seen many times, but not given proper attention.

oscar_peterson_statue.jpg

Figure 4: Oscar Peterson statue in Ottawa

This class also featured weekly “office hours” on Twitter (#jazzofficehour), where @UTJazzApp would answer questions real time. This also would not have scaled if everyone in the class had shown up, but in fact it turned out great. It seems just the right amount of people showed up each week to keep things lively without getting out of control.

I really can’t say enough good things about this course. There is talk of repeating it in January 2015. If you have any interest in jazz at all, you owe it to yourself to check it out!

Mongo MOOC

I just completed M101P: MongoDB for Developers! This is a free online course that uses the edX platform, but is not offered through edx.org. Instead, it is offered directly from MongoDB (formerly 10gen).

Certificate_640.png

As the name implies, it’s an introduction to MongoDB, a database that is not a relational database, but a document store. Last year, I took the Stanford database course which mentioned all sorts of databases, including MongoDB, but mostly focused on relational databases (there was a unit on NoSQL, but it had no exercises). As such, this course made a nice follow-up to that one.

Manipulexity v. Whipuptitude

One of the first lessons explains the motivation for MongoDB with a plot showing where Mongo fits in between the scalability of a key-value store and the functionality of an RDBMS.

Mongo_Manipulexity-v-Whipuptitude_640.png

Figure 1: Manipulexity v. Whipuptitude?

This struck me as analogous to Larry Wall’s motivation for creating Perl; he wanted something in between the manipulexity of C and the whipuptitude of shell! Since Perl is one of my favorite programming languages (by far the one I’ve used the most), this analogy bodes well! If Mongo fits into the database world similarly to the way Perl fits into the programming world, I think I will like it!

Ubuntu

The course recognizes only two kinds of computers: Macs and PCs. Since I use Linux machines almost exclusively, I have had to learn to cope with this view of the world. It’s pretty popular among the general population. But not for developers usually. It feels especially odd here since MongoDB is probably running on more Linux machines in the world right now than all other machines combined.

Fortunately, installing MongoDB on my laptop running Ubuntu was dead simple

sudo apt-get install mongodb-server mongodb-clients mongodb-dev

Ubuntu 13.10 has MongoDB 2.4.6, which is pretty up-to-date (the latest is 2.4.8). For this course, MongoDB 2.2 or newer will suffice. Note that Ubuntu 12.04 (the most recent LTS) supplies MongoDB 2.0. This lacks the aggregation framework, so it would not be sufficient for this course.

In the course video, they download MongoDB to a Mac, create a data directory in /data/db, and then start the server by changing to the bin directory and executing mongod. Using the Ubuntu package, the server is already running and it’s using /var/lib/mongodb as a data directory. So there’s nothing else to do!

$ mongo
MongoDB shell version: 2.4.6
connecting to: test
>

Here mongo, the command line MongoDB client, connects to our running server and gives us a prompt. It’s basically a JavaScript REPL with some extensions for doing MongoDB stuff

> 2 + 2
4
> 
bye

Easy peasy lemon squeezy!

Python

There are actually several versions of this course. This one uses Python. As such, we needed to install pymongo, the driver that enables our Python programs to communicate to MongoDB. In the course video, they download it manually and run easy_install as root…gah! Again, if you ignore that advice, it’s really quite simple to do

$ pip install pymongo

The course also creates a web application and for that they use Bottle, a nice little web framework that I was unfamiliar with (originally a fork of Flask, I guess). Again, it installs easily

$ pip install bottle

Even though both pymongo and Bottle work fine in Python 3, the course uses Python 2 for some reason. I found this particularly odd because I think of MongoDB as a new thing. I mean, their whole business is based around convincing people to eschew decades of database research and try this new way instead. If anyone was going to embrace Python 3, I would have thought it would be the MongoDB folks. Anyway, I started out converting everything to Python 3, but eventually I gave up and installed Python 2.7.6 and used that for the rest of the course.

The sample Python code left a lot to be desired, even given that it was Python 2. In addition to using the print statement instead of the print function and %s instead of string format, it was loaded with bare except statements. That was never good form, even in Python 2. And they incremented variables with “i = i + 1,” explaining that Python lacks i++ (yes, but it has i += 1, so we needn’t repeat the name). Also, they use classic classes everywhere!

There were also issues with the inline quizzes. This appeared to be because they were doing string matching when they should have been evaluating. For example, I got this wrong

Write the to code to initialize a list with the items "hammer", "nail"
and "wall" and assign the list to the variable named "things".

because I wrote

things = ['hammer', 'nail', 'wall']

and they only accepted

things = ["hammer", "nail", "wall"]

These, of course, are equivalent in Python.

Despite all of these issues, I think Python is a good choice for this course. I wish they had used an up-to-date Python and I wish they had used more idiomatic Python, but in the end it didn’t really affect the course too much. How to use MongoDB from Python was effectively communicated. Indeed, I’m sure you can extrapolate everything to any similar language. I tried several of the examples and exercises in Perl and things worked nearly the same way. I’m confident I could easily do things in Ruby as well.

edX

The bulk of the course went very well. The edX platform was easy to use (I had some difficulty with the edX demo course, but none with the MongoDB course). It’s very similar to Class2Go, which is what was used for the Stanford database class. Most lessons consisted of a video lecture, a quiz, and its answer. There is some discussion in some of the answers. It took a me a while to catch on to this. Early on, if I got the answer right, I didn’t look at the answer video. After I got a few wrong, it dawned on me that there was good stuff in some of those answer videos! After that I started watching all of them, even when I got the right answer.

The final exam was harder than I expected. Most of the course was pretty easy to follow, so I guess I was expecting a pretty easy final as well. That was not the case. It was actually pretty challenging. I got what was probably the easiest question wrong because I didn’t submit the answer correctly. It was a pretty straightforward update, but we weren’t supposed to merely provide the update command. Instead, we were meant to execute on some unseen database. The confusion was worsened because you couldn’t go back and look at your answer afterwards. In any case, I’m certain I did it right (I ran it locally), I just didn’t submit it right.

Summary

Overall, I think the course was very worthwhile. Compared to a relational database, MongoDB is a joy to use from programming languages and I think going through this course saved me a lot of the trouble of discovering stuff on my own.

If you’re interested, there’s another section starting soon!

All yarn gopher

CIMG8021.JPG

Figure 1: All yarn gopher

Here is a knitted Go gopher done with all yarn…no plastic eyes, no plastic nose, no felt teeth. I used the same yarn and needles as before, but I made a few changes.

Body (blue)

I started with Judy’s Magic Cast-On, but you can use any toe-up sock type cast-on. Using 4 DPNs, it divides nicely onto three needles.

CO4
Row 1: [k]
Row 2: [kfb] (8 sts)
Row 3: [k]
Row 4: [kfb] (16 sts)
Row 5: [k]
Row 6: [kfb] (32 sts)
Row 7: [k]
Row 8: [kfb, k7] (36 sts)
Rows 9 - 40: [k]
Row 41: [k2tog, k7] (32 sts)
Row 42: [k]
Row 43: [k2tog] (16 sts)
Row 44: [k]
Row 45: [k2tog] (8 sts)

CIMG8010.JPG

Figure 2: Make eyes before stuffing and closing

Eyes (white)

I did the eyes like the top of the head.

CO4
Row 1: k
Row 2: kfb (8 sts)
Row 3: k
Row 4: kfb (16 sts)
Row 5: k
BO

Use the yarn ends to attach the eyes to the face. Then use black yarn to add the centers of the eyes. I tried to make mine off-center, like in the original drawing, and they came out a little screwy. Eyes are important, so take care here.

Nose (tan)

CO4
Row 1: p
Row 2: k1, m1, k2, m1, k1 (6 sts)
Row 3: p
Row 4: k1, sl1, k1, pss0, k2tog, k1 (4 sts)

Teeth (white)

CO4
Row 1: sl1, p3
Row 2: sl1, k3
Row 3: sl1, p3
BO

Use the yarn ends to attach the teeth to the nose and both of those to the face. Then use black yarn to add the tip of the nose.

CIMG8011.JPG

Figure 3: Attach eyes

CIMG8012.JPG

Figure 4: Attach nose

Ears (blue)

Pick up 4 sts along head
Row 1-4: [k]
Row 5: [k2tog]
Break yarn and bind off, run yarn back to body and inside.

CIMG8013.JPG

Figure 5: Attach ears

CIMG8014.JPG

Figure 6: Use black yarn for the pupils and nose.

I did the arms, legs, and tail the same: four rounds of 4-stitch I-cord.

CIMG8015.JPG

Figure 7: You can attach the arms before closing up.

CIMG8016.JPG

Figure 8: Finish stuffing and close up before attaching the legs and tail.

Glenda, the Plan 9 Bunny

CIMG8004.JPG

Figure 1: Finished bunny, with image search in the background

This is my second attempt at Glenda, the Plan 9 bunny. The first one was improvised and then given away, so this time I tried to write down what I was doing.

Gauge hardly matters. I used worsted yarn and 4.5 mm needles.

I used plastic eyes and a plastic nose that clip on. If you don’t have those handy (or if you’re giving the bunny to a baby), you can improvise with black and pink yarn instead.

I save the ends from all of my knitting and normally I use that to stuff toys like this with. But since Glenda is all white, I didn’t want all the assorted colors to show through. So for this project, I used polyester fill from the craft store instead.

Body

I started with Judy’s Magic Cast-On, but you can use any toe-up sock type cast-on. Using 4 DPNs, it divides nicely onto three needles.

CO4
Row 1: k
Row 2: kfb (8 sts)
Row 3: k
Row 4: kfb (16 sts)
Row 5: k
Row 6: kfb (32 sts)
Row 7: k
Row 8: [kfb, k7] (36 sts)
Rows 9-35: k
Row 36: k17, turn
Row 37: sl1, p15, turn
Row 38: sl1, k14, turn
Row 39: sl1, p13, turn
Row 40: sl1, k
Row 41: k18, [k2tog] (27 sts)
STOP! Attach the eyes, nose, and ears before closing up.
Row 42: [k2tog] (14 sts)
Row 43: [k2tog] (7 sts)
Break yarn and run it through these 7 sts twice.

CIMG7982.JPG

Figure 2: Body of bunny (row 41?)

Ears

CO 8 in white
Rows 1-6: k3 white, k2 pink, k3 white
Rows 7-8: k8 white
Row 9: k2tog

CIMG7987.JPG

Figure 3: Ears

Nose

CO 6
Row 1: p
Row 2: sl1, k1, psso, k4, k2tog (4 sts)
Row 3: p1, p2tog, p1
BO

Place 12 mm pink plastic nose at top. Hot glue a small piece of white felt for teeth at bottom. Sew onto body using the tail from binding off.

CIMG7989.JPG

Figure 4: Nose

Finishing

I attached the eyes and nose before stuffing. But I put most of the stuffing in before attaching the ears. I think placement of the ears is important; we’re not making just any cute litte bunny, we’re making Glenda. She’s a little off kilter, so you want to shape her a bit after stuffing and then place the ears just so.

CIMG7990.JPG

Figure 5: Stuff before placing ears?

The legs are going to be formed from those short-rows at the end of the body

CIMG7993.JPG

Figure 6: Form legs by stitching

Make a pom-pom for a tail! You can buy little gizmos to help you make pom-poms, but your fingers work as well.

CIMG7996.JPG

Figure 7: wrap yarn around two fingers

CIMG7997.JPG

Figure 8: Tie off and cut

CIMG7999.JPG

Figure 9: Now trim

Leave yourself a long enough tail to attach the pom-pom with.

CIMG8002.JPG

Figure 10: Finished

Go Gopher

CIMG7979.JPG

Figure 1: Finished gopher, with image search in the background

Here is my second attempt at a knitted Go gopher. The first one was improvised and then given away. This time I tried to keep track of what I did as I went along. I had a lot more trouble this time and I’m not as happy with the result. Especially the nose. I might have to rework that. Check back for updates.

Gauge hardly matters. I used worsted yarn and 4.5 mm needles.

I used plastic eyes and a plastic nose that clip on. If you don’t have those handy (or if you’re giving the gopher to a baby), you can improvise with black yarn instead.

I save the ends from all of my knitting and use that to stuff toys like this with. If you don’t have a bag of “yarn ends” handy, you can buy polyester fill at a craft store.

The arms, legs, and tail are I-cord. Nothing could be simpler. It’s just like knitting in the round, only on just two needles. You’re still going around in a circle, but with only four or five stitches per round, it’s not worth it to change needles.

Body

I started with Judy’s Magic Cast-On, but you can use any toe-up sock type cast-on. Using 4 DPNs, it divides nicely onto three needles.

CO6
Row 1: [k]
Row 2: [kfb] (12 sts)         # 4 sts per needle
Row 3: [kfb] (24 sts)         # 8 sts per needle
Row 4: [k]
Row 5: [kfb, k7] (27 sts)     # 9 sts per needle
Row 6: [kfb, k8] (30 sts)     # 10 sts per needle
Row 7: [kfb, k9] (33 sts)     # 11 sts per needle
Row 8: [kfb, k10] (36 sts)    # 12 sts per needle
Row 9-25: [k]                 # about 7 or 8 cm from CO
Row 26: [k2tog, k10] (33 sts)
Row 27: [k2tog, k9] (30 sts)
Row 28: [k2tog, k8] (27 sts)
Row 29: [k2tog, k7] (24 sts)  # about 10 cm
STOP! Assemble and stuff the gopher before finishing.
Row 30: [k2tog] (12 sts)
Bind off (break yarn and run through remaing loops twice)

CIMG7965.JPG

Figure 2: Body after increases, but before decreases (row 25?)

Eyes (white)

I adapted the knit a circle instructions here to make the white disks for the eyes. This is a bit fiddly. The first gopher I did had crocheted eyes that my wife made for me. I wanted to make an “all knit” pattern, so I worked this out, but if you know how to crochet (or if you have a crocheter in the house like I do!), consider doing that instead.

CO 1
Row 1: k1, p1, k1 in the same stitch. (3 sts)
Row 2: Turn the needle and purl across the row.
Row 3: Turn the needle again, kfb all stitches. (6 sts)
Row 4: Divide onto three DPNs, join, and knit around.
Row 5: Kfb all stitches. (12 sts)
Row 6: Knit around.
Row 7: [Kfb, K1] around. (18 sts)
Bind off, leaving a long tail.

Place 9 mm black plastic eyes in centers. Position eyes on body and sew in place with the tail from binding off.

CIMG7967.JPG

Figure 3: Knitted eyes, one with plastic insert.

Nose (tan)

CO 5
Row 1-3: sl1, k4
Break yarn and bind off, leaving a tail to attach with.

Place 12 mm black plastic nose at top. Hot glue a small piece of white felt for teeth at bottom. Sew onto body.

CIMG7969.JPG

Figure 4: Nose with plastic nose inserted and felt teeth glued on.

Ears (blue)

Pick up 4 sts along head
Row 1-4: [k]
Row 5: [k2tog]
Break yarn and bind off, run yarn back to body and inside.

CIMG7971.JPG

Figure 5: Gopher with eyes, nose, and ears.

Arms and Legs (tan)

CO5 
Row 1-4: knit I-cord
Row 5: k2tog, k1, k2tog
BO and run tail down through center of I-cord to the bottom.

CIMG7975.JPG

Figure 6: You can stuff the gopher after attaching the arms, but then close up before attaching the legs and tail.

Tail (tan)

CO4 
Row 1-4: knit I-cord
BO and run tail down through center of I-cord to the bottom.

CIMG7977.JPG

Figure 7: With the body stuffed and closed, attaching the legs and tail is a bit fiddly, but not too bad.