Ethical Programming

xkcd on good code

Don’t let anyone tell you that as a programmer you don’t have to make moral or ethical decisions. Every time you decide that making users feel stupid is better than fixing your code, you’re making an ethical decision. – Joel Spolsky

This may belong in a separate post, but while we’re on the subject of programming, I am trying to come up with a project that will help researchers/bloggers/writers/academics save time/money/frustration. The requirements are that it be doable within the next month or so (at least a minimally viable version) while I work on other projects, and that it have a substantial Python component with maybe some R, SQL, or Django thrown in. Requests or suggestions in the comments or by email are welcome.

[quote via @newsyc20]

Wednesday Nerd Fun: The iPad of 1935

"The Book Reader of the Future," April, 1935


The April, 1935 issue of Everyday Science and Mechanics included this nifty invention which was to be the next logical step in the world of publishing. Basically a microfilm reader mounted on a large pole, the media device was supposed to let you sit back in your favorite chair while reading your latest tome of choice.

“It has proved possible to photograph books, and throw them on a screen for examination, as illustrated long ago in this magazine. At the left is a device for applying this for home use and instruction; it is practically automatic.”

Additional text accompanying the illustration reads, “You can read a ‘book’ (which is a roll of miniature film), music, etc., at your ease.”

Thank goodness that Steve Jobs had a knack for design.

Micro-Institutions Everywhere: Bike Paths

Some think, including many Dutch themselves, that bike paths have always been there…. Cycle paths weren’t really necessary [when] cyclists outnumbered auto traffic by far. After WWII, everything changed.

Specifically, Dutch incomes went up dramatically in the post-war boom, more people bought cars, and many more lane-miles for cars were built. As auto traffic grew, the risk for cyclists–especially children–increased noticeably. During the oil crisis of the early 1970′s, the government instituted “car-free Sundays,” which showed people that they could still get around cities without their cars.

In 1975, the government created “demonstration routes” in The Hague and Tilburg to encourage cycling. The video says that “in retrospect, this was the start of the modern cycling movement” in the Netherlands.

Why do bike paths qualify as micro-institutions? First and most simply, they are coordination devices. According to the Pedestrian and Bicycle Information Center, “Bicycle lanes make the movements of both motorists and bicyclists more predictable and as with other bicycle facilities there are advantages to all road users in striping them on the roadway.”

Second, in this case they were clearly a result of government policy to encourage a specific behavior. Third, protestors played an interesting role: see the video at about 6 minutes in for an example of an “informal” bike path that protestors created by painting the pavement. Later on, it was formalized into a modern bike path.

None of this is to suggest, as some would, that the greatest need of the US today is more bike lanes. Rather, it is to show how quickly an informal micro-institution can become formalized, and then how soon people think of it as something that has “always been there.”

[via @brainpicker] 

PyCon 2012 Video Round-Up

The videos from PyCon 2012 are posted. Here are the ones I plan to watch, along with their summaries:

Checking Mathematical Proofs Written in TeX

ProofCheck is a set of Python scripts which parse and check mathematics written using TeX. Its homepage is Unlike computer proof assistants which require immersion in the equivalent of a programming language, ProofCheck attempts to handle mathematical language formalized according to the author’s preferences as much as possible.

Sketching a Better Product

If writing is a means for organizing your thoughts, then sketching is a means for organizing your thoughts visually. Just as good writing requires drafts, good design requires sketches: low-investment, low-resolution braindumps. Learn how to use ugly sketching to iterate your way to a better product.

Bayesian Statistics Made (as) Simple (as Possible)

This tutorial is an introduction to Bayesian statistics using Python. My goal is to help participants understand the concepts and solve real problems. We will use material from my (nb: Allen Downey’s) book, Think Stats: Probability and Statistics for Programmers (O’Reilly Media).

SQL for Python Developers

Relational databases are often the bread-and-butter of large-scale data storage, yet they are often poorly understood by Python programmers. Organizations even split programmers into SQL and front-end teams, each of which jealously guards its turf. These tutorials will take what you already know about Python programming, and advance into a new realm: SQL programming and database design.

Web scraping: Reliably and efficiently pull data from pages that don’t expect it

Exciting information is trapped in web pages and behind HTML forms. In this tutorial, you’ll learn how to parse those pages and when to apply advanced techniques that make scraping faster and more stable. We’ll cover parallel downloading with Twisted, gevent, and others; analyzing sites behind SSL; driving JavaScript-y sites with Selenium; and evading common anti-scraping techniques.

Some of it may be above my head at this stage, but I think it’s great that the Python community makes all of these resources available.

Wednesday Nerd Fun: Emojicons

Ever feel the need to express yourself with say, a bear flipping a table, and think ‘I wish there was an emoticon for that’? Well, look no further. Emojicons is a website dedicated to providing a repository of texto-graphical expressions for your every whim.

Here’s the aforementioned bear:

ʕノ•ᴥ•ʔノ ︵ ┻━┻

or maybe you’d rather chill out with head phones:


Whatever your fancy this week, take a minute to browse their site and see if you can come up with some other creative expressions. Bonus points for the first person who can sneak these into a footnote or the body text of a published journal article.

Illicit Trade and International Relations

The debate of whether bilateral (licit) trade increases or reduces the risk of conflict between two countries is ongoing, but the ‘yeas’ have it for now. But what about illicit trade?

Sheena Chestnut Greitens, a doctoral candidate at Harvard, discussed this last weekend in the context of North Korea. She has this advice for an aspiring kingpin:

First, find the money. Kim Jong-un seems to have done that. One of the last photos released of Kim Jong-il shows him riding a supermarket escalator. Behind him are Kim Jong-un and Jon Il-chun, manager of the infamous Bureau 39.

Second, control the people who earn the money. Illicit activity brings the risk of freelancing, especially when you’re forced to let others do the distribution. As North Korea outsourced the drug trade, its profit margins dropped — and more and more insiders skimmed off the system to line their pockets. Today, reports indicate that methamphetamine is widely used in North Korea (partly because it dulls hunger pains), and the state is cracking down on the trade it once monopolized. Even Kim Jong-il couldn’t maintain perfect control and had to send operatives abroad to retrieve misbehaving agents. These are delicate tasks easily botched by a novice.

Finally, keep the money coming. Criminal activity was never North Korea’s ultimate objective; the aim was always hard currency. Kim Jong-un needs cash without political conditions to stay in power. But there aren’t many good options for getting it these days, which is why North Korea is likely to pursue new and expanded forms of illicit activity.

Further reading: the SINO-NK blog has a good follow-up here.

Sentences to Ponder, Egypt Edition

Image Source: Globe and Mail

All from the same Washington Post article:

There is no public data on crimes, and requests for interviews with security officials were not granted, but in Cairo the stories are enough to strike fear….

Since the revolt last winter he’s seen a significant increase in kidnappings and armed carjackings….

“It’s not just lawlessness. It’s a complete lack of security,” said Fadia Abu Shahba, a criminal researcher at the National Center for Social and Criminal Studies. “There was such anger towards the police from the people because the people were attacked. People would curse them and hit them. But they are our children and we need security. Security is one of our most precious rights.”

In her research on carjackings Abu Shahba found that criminals who once used more benign weapons such as small knives and sticks had graduated to machine guns and rifles. She said in 2011 there were more than 40,000 carjackings in Egypt compared with about 4,000 in 2010.

Is security more about perception or reality?

Wednesday Nerd Fun: Every Plot, Ever

Is it possible to boil the plots of all great literature down to a few formulas? Whether you sympathize with the effort to reduce literature to a science or not, you have to admire the efforts. A brief history from Michelle Legro:

In 1894, French critic Georges Polti recognized thirty-six possible plots, which included conflicts such as Supplication, Pursuit, Self-sacrifice, Adultery, Revolt, the Enigma, Abduction, and Disaster. In 1928, dime novelist William Wallace Cook, author of Plotto: The Master Book of All Plots, did him one better, cataloging every narrative he could think of through a method that bordered on madness. His final plot count? 1,462

While still a young director in England, Alfred Hitchcock requested the book from America, and the creator of the courtroom drama Perry Mason claimed he had learned a great deal from it. The success of Plotto inspired other write-for-pay miracle workers. In 1931, screenwriter Wycliffe Hill declared that he had invented a “Plot Robot,” which turned out to be nothing more than cardboard wheel of options that would help you choose a plot in the same way you might choose a color for your living room.

Santiago Ortiz maps the Illiad, via FlowingData

Michelle’s post largely centers around the history of Plotto, which was reissued last month. She mentions the “exceedingly” complicated categorization system, which seems to rely on reduce the story to two key characters and everyone else is understood by their relation to these two. But it turns out that Plotto was not the last effort to categorize plots. Scott Page, who is currently teaching the University of Michigan’s online Model Thinking course, recently shared a chapter from one of his books in which he compares models and narratives:

Indulge me a moment’s description of the Great Books. Hutchins and Adler, include four hundred and thirty one texts by seventy-three authors, an entire bookshelf. Even if someone did read that entire bookshelf, the more troublesome problem would be making sense of them all – separating transcendent ideas from plot. What are we to take from the Odyssey: That you should put wax in your ears? That you should remain faithful to your spouse? Or perhaps, that you should build an unusually large bed?

This dastardly duo: the time commitment and the problem of separating anecdote from deep analogy led Adler and Hutchins to produce the Syntopicon: a glossary of sorts to the Great Ideas inside the Great Books. The Syntopicon debuted in 1952. Inside, it listed one hundred and two Great Ideas including as imagination, physics, liberty and death. Connecting all of these ideas back to the texts required prodigious outlays of time and effort, and, one can only imagine, produced long discussions over interpretations. Why or how they decided to stop at one hundred and two is mystifying to me. Had they thought of just two more, they could have released them as a bridge set of playing cards. As for the wax ears of Odysseus’s crew, the faithful Penelope, and the enormous bed, these would seem to fall into the categories desire, prudence, and symbol, so all should make the list.

I mention the Syntopicon because the Great Models align more closely with the Great Ideas than with the Great Books. Models formalize many of the Great Ideas, though not all (dialectic and prophecy would be difficult to model). Hutchins and Adler did not devote much attention to models. In fairness, the tools we use to make sense of have changed since the Syntopicon was created. When they began selecting the Great Books, the library from which they chose contained few books from outside the natural sciences that contained models. Darwin didn’t use models. Neither did Adam Smith. Not because Darwin and Smith’s ideas couldn’t have been improved with models (they have been!), but because the relevant models had yet to be developed. Today if you take a course on evolution or economics, you learn models. That’s also true if you take courses in psychology, anthropology, or archeology.

Besides Page’s take on the role of models, the main thing I take away from this is the large variation in the number of plots that each project ultimately reduced to. Is there a true number? Probably not. (Interestingly enough, Adler later came out with a book called Six Great Ideas.) But as with all models, the interesting aspects go beyond the results, to how the model’s creator chose to simplify reality. A more in-depth exploration would be fun, but this post is already getting quite long. Follow the links for more fun.

Note: This post was originally going to riff on the quant/qual divide in political science, but I was afraid some readers might take it too seriously and miss the spirit of these midweek posts.  

How to Count Words in LaTex Documents

One thing that can be hard to adjust to for new LaTeX users is not being able to easily get a word count relative to other programs. Now there is a solution, thanks to Matthias Orlowski and Alex Iliopoulos. I share Matthias’s instructions here, with a couple notes of my own at the end.

1. Check whether Perl is installed by typing “which perl” in Terminal. That should be the case since Mac OS X ships with an installation of Perl.

2. Check whether texcount is installed by typing “which texcount” to Terminal. That should also be the case if you installed MacTex recently. If not, install it via TeXLive.

3. Copy the code below to your Preferences.el file which should be located at ~/Library/Preferences/Aquamacs Emacs

; count words in latex docs
(defun latex-word-count ()
  (shell-command (concat "PATH "
    "-inc "; texcount option (set to count documents included via \input)

; that's [ctrl-c w] as the hotkey
(global-set-key (quote [f6]) 'latex-word-count)

“PATH ” is the path returned by ‘which texcount’ in (2), and the space at the end is important.

4. Restart Aquamacs and open a Tex file. Hit F6 and see the magic happen!

Now, obviously these instructions are only for OS X, but I would be happy to share Windows instructions if someone wants to adapt them. The first thing to look out for is that on recent OS X Macbooks the default for F6 is to brighten the keyboard backlight. You can change this by going into the Keyboard section on System Preferences and selecting “Use all F1, F2, etc. keys as standard function keys.” The second potential problem is if the path of the Tex file you are using includes spaces; this can possibly be addressed by putting a forward slash (\) instead of the space, but I cannot verify that from experience.

If you run into other issues with this script, or have new adaptations of it, feel free to leave them in the comments.

Micro-Institutions Everywhere: Pirates

Image credit: Matt Collins/Scientific American

Kokai: What’s the most important thing we should know about how pirates acted economically?

Leeson: I think the most important takeaway from the economics of piracy is the idea of self-governance. It’s common to think about social rules, some system of law and order, as only being capable of being provided by a state, by a government, a monopoly on the use of force. And pirates give us pause to rethink that conventional wisdom, because pirates as outlaws, of course, couldn’t rely on the formal apparatuses provided by the state as a way to produce social order among them. …

It’s not only that they had rules, they had very specific, detailed rules — rules that were surprisingly, at least for pirates anyway, rather puritanical. For example, it appears to be the case that on some pirate ships at least, drinking was quite restricted. Bedtimes were restricted; they had an early bedtime of 8 o’clock on one ship. Gambling was prohibited. Allowing women [was] prohibited on pirate ships.

From the Carolina Journal interview with Peter Leeson. Leeson is a professor at George Mason University, and the author of The Invisible Hook: The Hidden Economics of Pirates and numerous journal articles. A good place to start with further reading is here.