Easiest and hardest classes to teach

I’ve taught a variety of math classes, and statistics has been the hardest to teach. The thing I find most challenging is coming up with homework problems. Most exercises are either blatantly artificial or extremely tedious. It’s hard to find moderately realistic problems that don’t take too long to work out.

The course I’ve found easiest to teach has been differential equations. The course has a flat structure: there’s a list of techniques to cover, all roughly the same level of difficulty. There are no deep analytic or philosophical issues to skirt around as there are in statistics. And it’s not hard to come up with practical applications that can be worked out fairly easily.

Related post: Impure math

Software to slice bread

In the dark ages of programming, functions acted on data. To slice your bread, you passed a bread data structure to a slice function:

    slice(bread);

Then came object oriented programming. Instead of having an external function slice our bread, we would ask the bread to slice itself by calling the slice method on a bread object:

    bread.slice();

Obviously a vast improvement.

Now object oriented programming has become more refined. First we create a bread-slicing object and then we simply pass bread objects to the slice method on the bread-slicer:

    BreadSlicer slicer = new BreadSlicer();
    slicer.slice(bread);

More food analogies to software development

Digital desk, analog desk

Austin Kleon has an interesting idea for setting up a workspace: have a digital desk and an analog desk.

I have two desks in my office — one is “analog” and one is “digital.” The analog desk has nothing but markers, pens, pencils, paper, index cards, and newspaper. Nothing electronic is allowed on that desk. That’s where most of my work is born … The digital desk has my laptop, my monitor, my scanner, and my drawing tablet. This is where I edit and publish my work.

From Steal Like an Artist.

The context of this quote is a discussion of how we think differently depending on the tools we use. I wrote something along these lines a while back: Create offline, analyze online.

Misplaced decimal

This evening I ran across a dialog that suggests that decimal notation is wrong.

It happened when I started learning about decimals in school. I knew then that ten has one zero, a hundred has two, a thousand three, and so on. And then this teacher starts saying that tenth doesn’t have any zero, a hundredth has only one, a thousandth has only two, and so on. … Only much later did I have enough perspective to put my finger on the problem: The decimal point is always misplaced!

Source: Conics. Emphasis in the original.

The proposed solution is to put the decimal point above the units position rather than after it. Then the notation would be symmetric. For example, 1000 and 1/1000 would look like this:

Of course decimal notation isn’t likely to change, but the author makes an interesting point.

iPad as hip flask

I reread Paul Graham’s essay The Acceleration of Addictiveness after a friend quoted it in a blog post explaining why he is taking an indefinite hiatus from social media. I hadn’t noticed this gem in the footnotes when I first read Graham’s essay:

Several people have told me they like the iPad because it lets them bring the Internet into situations where a laptop would be too conspicuous. In other words, it’s a hip flask.

Related post: How to neutralize intelligence

Monkeying with Bayes’ theorem

In Peter Norvig’s talk The Unreasonable Effectiveness of Data, starting at 37:42, he describes a translation algorithm based on Bayes’ theorem. Pick the English word that has the highest posterior probability as the translation. No surprise here. Then at 38:16 he says something curious.

So this is all nice and theoretical and pure, but as well as being mathematically inclined, we are also realists. So we experimented some, and we found out that when you raise that first factor [in Bayes’ theorem] to the 1.5 power, you get a better result.

In other words, if we change Bayes’ theorem (!) the algorithm works better. He goes on to explain

Now should we dig up Bayes and notify him that he was wrong? No, I don’t think that’s it. …

I imagine most statisticians would respond that this cannot possibly be right. While it appears to work, there must be some underlying reason why and we should find that reason before using an algorithm based on an ad hoc tweak.

While such a reaction is understandable, it’s also a little hypocritical. Statisticians are constantly drawing inference from empirical data without understanding the underlying mechanisms that generate the data. When analyzing someone else’s data, a statistician will say that of course we’d rather understand the underlying mechanism than fit statistical models, that’s just not always possible. Reality is too complicated and we’ve got to do the best we can.

I agree, but that same reasoning applied at a higher level of abstraction could be used to accept Norvig’s translation algorithm. Here’s this model (derived from spurious math, but we’ll ignore that). Let’s see empirically how well it works.

Comedic genealogy

Austin Kleon on imitation and originality:

Johnny Carson tried to be Jack Benny but ended up Johnny Carson. David Letterman tried to copy Johnny Carson but ended up David Letterman. And Conan O’Brien tried to be David Letterman but ended up Conan O’Brien. In O’Brien’s words, “It is our failure to become our perceived ideal that ultimately defines us and makes us unique.”

Stolen from Steal Like an Artist

More posts on originality

Machine Learning for Hackers

Drew Conway and John Myles White have a new book out, Machine Learning for Hackers (ISBN 1449303714). As the name implies, the emphasis is on exploration rather than mathematical theory. Lots of code, no equations.

If you’re looking for a hands-on introduction to machine learning, maybe as a prelude to or complement to a more theoretical text, you’ll enjoy this book. Even if you’re not all that interested in machine learning, you might enjoy the examples, such as how a computer could find patterns in senatorial voting records and twitter networks. And R users will find examples of using advanced language features to solve practical problems.

Shuffling Emacs windows

Emacs lets you split your screen into windows, what other applications might call panels. This can be quite handy. However, I often want to move the windows around and I couldn’t find how to do that. I asked Xah Lee, he posted the question on G+, and Mark Hepburn answered with a pointer to code that does what I wanted: buffer-move.el

(Strictly speaking the windows don’t move; the buffers move between the windows. But I think of it as moving the windows around.)

Lucas Bonnet explains how his buffer-move works:

This file is for lazy people wanting to swap buffers without
typing C-x b on each window. This is useful when you have :

+--------------+-------------+
|              |             |
|    #emacs    |    #gnus    |
|              |             |
+--------------+-------------+
|                            |
|           .emacs           |
|                            |
+----------------------------+

and you want to have :

+--------------+-------------+
|              |             |
|    #gnus     |   .emacs    |
|              |             |
+--------------+-------------+
|                            |
|           #emacs           |
|                            |
+----------------------------+

This is exactly what I had in mind. I did have one problem, however, though it wasn’t with buffer-move per se. The file defines four functions for moving buffers between windows and suggests key bindings. The author says he uses the following.

(global-set-key (kbd "<C-S-up>")     'buf-move-up)
(global-set-key (kbd "<C-S-down>")   'buf-move-down)
(global-set-key (kbd "<C-S-left>")   'buf-move-left)
(global-set-key (kbd "<C-S-right>")  'buf-move-right)

This works fine, except when one of the windows contains an org-mode buffer. Org-mode has its own bindings for control-shift-up etc.

I learned that global-set-key does not globally set a key binding! Well, it does as long as there are no conflicts. But local bindings, i.e. bindings specific to a mode, have precedent. After some searching and trail-and-error, I added the following to my .emacs to override org-mode’s local bindings.

(add-hook 'org-mode-hook '(lambda ()
   (local-set-key [C-S-up]    'buf-move-up)
   (local-set-key [C-S-down]  'buf-move-down)
   (local-set-key [C-S-left]  'buf-move-left)
   (local-set-key [C-S-right] 'buf-move-right)))

Clipboard history

The Windows clipboard only remembers the most recent thing you copied [1]. This can be very disappointing. Maybe you cut a large block of text intending to paste it somewhere, but without thinking you cut something else, and then realize you’ve just wiped out your first cut. Here are a few possible alternatives for Windows, MS Office, and Emacs.

A few years ago I tried ClipX, a free clipboard history manager for Windows, based on Jeff Atwood’s recommendation. It worked OK at first, but then I had problems with it and stopped using it. It looks like the software hasn’t been updated since 2008. If you know of a better alternative, please let me know. Also, please let me know if you have suggestions for Ubuntu.

(Update: See the comments for numerous suggestions of ClipX-like products. Also, see PHenry’s comment about clipboard history in Visual Studio.)

MS Office has its own clipboard that will store 24 entries. It stores things that have been copied either inside or outside of Office applications, but you can only paste from the Office clipboard using an Office application.

Emacs has a “kill ring” which is essentially a clipboard. It also has “registers” which are like named clipboard items.

Yesterday Emacs Knight posted a handy little bit of code for viewing your kill ring.

    (global-set-key "C-cy" '(lambda ()
        (interactive) (popup-menu 'yank-menu)))

If you add this to your .emacs file, you can type ctrl-c y to pull up a little GUI menu displaying the contents of your kill ring.

[1] I’ve heard that Windows actually keeps more clipboard history, but it doesn’t provide a user interface for accessing that history. I don’t know whether this is true. But if it is, you could access the history programmatically. Maybe Office isn’t maintaining its own clipboard but just exposing more of the system clipboard.