Jan 26 2009

Review: The Design of Everyday Things by Donald Norman

I don’t have much to say about this book. Originally called The Psychology of Everyday Things, it’s a long musing on the poor design that surrounds us. I found it reasonably interesting, but I think I’d have preferred a more rigorous approach than the loose and chatty style Norman uses. All the same, it’s certainly affected the way I look at things around me and it’s going to have a permanent place on my bookshelf for whenever I’m called upon to design stuff.


Jan 24 2009

Review: The Mysteries of Pittsburgh by Michael Chabon

My first encounter with Michael Chabon’s work was the film adaptation of his second novel, Wonder Boys, which I saw on video while I was working in a video rental store. I watched a lot of movies in the six months I was there (free rentals were one of the perks) otherwise I might have missed it entirely, as so many other people did. It was one of my favourite movies for quite a while after that. I get into quite a few authors through film, but for some reason the fact that Wonder Boys was an adaptation completely passed me by. In fact, I still haven’t read it (though it’s on my list). So the first Chabon novel I’ve read is his debut, The Mysteries of Pittsburgh.

It’s a coming-of-age story. The feckless Art Bechstein, recently graduated student of the University of Pittsburgh spends the summer falling in love with a Machiavellian young man and a strange-but-interesting girl. Chabon’s style is elaborate enough to entertain. Unfortunately the plot is slight enough that it nearly collapses from the weight of all those baroque descriptions.

I really like the way Chabon writes, but in this debut novel, what he writes about just isn’t satisfying. There are several threads to the novel that slowly draw together, but they lumber along and the final collision is predictable and unspectacular. As the novel progressed beyond its lively opening chapters, I found it increasingly difficult to care about the events. Maybe the bisexual plot-line was more interesting in 1988, but twenty-years on there’s bisexual characters even in TV shows like Doctor Who.

But it’s Chabon’s first novel, and despite the nitpicking above, I did enjoy it. So I’m definitely going to pick up Wonder Boys at some point; after all I already know that enjoyed that plot.


Jan 23 2009

Learning Java: Brute Force Sudoku Solver

The next in my series of teach-myself-java programs is a brute force Sudoku solver. You give it a file (or a list of files) containing 9×9 sudoku grids (empty cells are represented with “-” or “0″), and it gives you the solution:

C:\Home\working\java\Sudoku>type problem1.txt
----6---9
-6----3-1
2----98--
196--2--8
---3-8---
8--9--175
--17----4
6-7----8-
4---9----

C:\Home\working\java\Sudoku>java -jar BruteForceSolver.jar problem1.txt
318267549
769854321
245139867
196572438
574318296
832946175
921783654
657421983
483695712

Downloads:
bruteforcesolver.zip – source files.
bruteforcesolver.jar – java archive.


Jan 15 2009

Review: The Motorcycle Diaries by Ernesto ‘Che’ Guevara

Che Guevara’s never been one of my heroes and I’ve never owned any item of apparel, any badges, or any poster featuring the famous portrait captured in Guerrillero Heroico. I tend to associate that photo (I bet you know which one I mean without clicking on that link) with a rather shallow affectation of rebellion. It’s not that I revere him, or think his image needs protection, but if I had my way anyone wearing a t-shirt featuring El Che’s image should have it confiscated if they can’t provide brief biographical details.

“Yes officer, certainly, Che was born in Argentina, met Fidel Castro and joined the 26th of July movement, helped overthrow Batista, the Cuban dictator and was killed while trying to foment revolution in Bolivia.”

I think this rule should apply to anyone who wears someone else’s image, but Che Guevara is a morally complicated figure, who had people executed – which makes it slightly more important than knowing who, for example, André the Giant is. I’m sure that plenty of people who do have more than a cursory knowledge of Guevara choose to wear his image, but I’m far from certain that they’re in the majority.

I don’t approve of Guevara’s actions or his philosophy strongly enough to wear his image myself (I’d also prefer people like me to not assume that I’m shallow). I do think he was a courageous man who remained true to himself and his principles, even if I don’t like where those principles led him. Not that my opinion on him is all that important, but that’s what I brought with me when I started reading The Motorcycle Diaries, the travelogue of his journey across South America as a young man.

Guevara’s travels and adventures are charming and laddish, full of drama, narrow escapes and the brief friendships of the road. Guevara has an eye for detail and presents a ground-eye view of 1950′s South America, with all its post-colonial poverty and majesty. While the adventure stuff is pretty standard fare, Guevara is at his best when describing the people and places he finds himself in. I particularly like his description of a festival in Lima:

We arrived as the bullfight was starting and just as we entered, a novitiate was killing a bull, but not in the normal way by a coup de grace. As a result, the bull was suffering, laid out on the ground, while the toreador tried to finish it off and the public shouted. For the third bull there was considerable excitement in the air, but that was it. The fiesta closed with the almost unnoticed death of the sixth bull. Art, I see none; courage, a certain level; skill, not much; excitement, relative. In summary, it all depends what there is to do on a Sunday.

It makes for interesting reading, but if they had been written by someone other than Guevara, I’m not sure that it would have the same effect. What makes The Motorcycle Diaries interesting is the knowledge that this twenty-three year old boy would, just a few years later, become an armed revolutionary, then a martyr, then a cultural icon. As the book progresses you get the feeling that Guevara’s political views are slowly forming as he becomes more worldly and meets with poverty and injustice.

I’d probably have got more from the book if I bought into the pop-culture status of Guevara as Saint of Revolutions. As it is, The Motorcycle Diaries were an enjoyable distraction from a miserable British winter. And if I do ever find myself in a Che t-shirt, I’ll be justified in keeping it.


Jan 14 2009

Review: Tropic of Cancer by Henry Miller

What is there to say about Henry Miller’s Tropic of Cancer, his chaotic, semi-autobiographical rant of a novel? Since it’s widely regarded as one of the more important works of 20th century literature, probably very little that’s new or interesting. But here goes…

It’s interesting how Tropic of Cancer encapsulates the essentials of gonzo journalism nearly forty years before Hunter S. Thompson came up with the term. With his goal of “recording of all that which is omitted in books”, Miller engages in a hyper-real blending of fact and fiction, with prose that veers between confessional and psychedelic. Like Raoul Duke of Fear and Loathing in Las Vegas, he’s a morally questionable, yet eminently likable protagonist. In every way, Tropic was way ahead of its time.

If I knew more about 1930′s literature, I’d situate the book in the context of its times. But the best I could do is some vague babbling about D.H. Lawrence and James Joyce, so I won’t embarass myself by trying. But I prefer Miller to either of them. Lawrence feels so much more self-conscious and Joyce much more impenetrable. Miller’s work remains accessible today in a way that other literature of the period hasn’t, at least for me. While there’s not really a coherent story, there’s certainly a coherent philosophy and it’s expressed in every way that Miller can find. I think this passage sums it up best:

Once I thought that to be human was the highest aim a man could have, but I see now that it was meant to destroy me. Today I am proud to say that I am inhuman, that I belong not to men and governments, that I have nothing to do with creeds and principles. I have nothing to do with the creaking machinery of humanity – I belong to the earth!

Tropic is a manifesto of liberation, it’s about Miller’s struggle to break free from every kind of repression. The many explicit and often-crude sexual references are justified in a way that would be prurient in most other works. It’s not the celebration of sex that Lawrence wrote about, or Joyce’s symbolic sexuality, it’s sex as a rejection of repression, as a blatant and fierce act of rebellion. It’s not all about sex – again and again in Tropic Miller breaks free from every attempt to constrain him, culminating in an frenetic episode in which Miller becomes a liberator, decisively getting a friend out from a marriage he was forced into. The intention of the novel wasn’t just to describe freedom, but to actively inspire it in others.

It’s compelling and direct. Maybe it’s just as powerful a book today as it was when it was published in 1934. I don’t know – it’s not like I was around then to compare. But it’s as powerful for me today as it was when I first read it at 16.


Jan 14 2009

Learning Java: Monty Hall Simulation

I’ve always found the Monty Hall problem kind of interesting. So I wrote a little Java program to demonstrate it. Here’s an example of the output:

C:\Home\working\java\MontyHall>java -jar MontyHallTest.jar 10000
Sticking with the same box wins 3368 out of 10000, or 33.68%
Switching boxes wins 6682 out of 10000, or 66.82%

Downloads:
montyhall.zip – source files.
montyhalltest.jar – java archive.


Jan 13 2009

Learning Java: Guess The Number

I’ve just finished reading the section on Basic I/O on the Java essential classes trail. So I put together a little Guess-The-Number game.

import java.io.*;
import java.lang.Math.*;
 
public class NumberGame {
    private Console c;
    private int upperBound;
    private int lowerBound;
 
    public NumberGame() {
        c = System.console();
        if (c == null) {
            System.err.println("Unable to aquire console. Exiting...");
            System.exit(1);
        }
    }
 
    private void playGame() {
        c.format("Welcome to the guess-the-number game!%n");
        c.format("Think of a number between 1 and 100 and I'll try to " +
                 "guess it!%n");
        upperBound = 100;
        lowerBound = 1;
        boolean finished;
        do {
            finished = makeGuess();
        } while (finished == false);
        c.format("Thank you for playing!%n");
    }
 
    private boolean makeGuess() {
        if (upperBound == lowerBound) {
            makeAccusation(upperBound);
            return true;
        }
        else {
            int choice = ((upperBound - lowerBound) / 2) + lowerBound;
            if (Math.random() < 0.5) {
                boolean answer = askYesOrNo(String.format("%nIs your " +
                                   "number higher than %d? ", choice));
                if (answer) {
                    lowerBound = choice + 1;
                }
                else {
                    upperBound = choice;
                }
            }
            else {
                boolean answer = askYesOrNo(String.format("%nIs your " +
                                   "number lower than %d? ", choice));
                if (answer) {
                    upperBound = choice;
                }
                else {
                    lowerBound = choice - 1;
                }
            }
        }
        return false;
    }
 
    private boolean askYesOrNo(String query) {
        int answer = -1;
        String result;
        char resultChar = ' ';
        while (true) {
            result = c.readLine(query);
            if (result != "") {
                result = result.toLowerCase();
                if (result.length() > 0) {
                    resultChar = result.charAt(0);
                    if (resultChar == 'y') {
                        return true;
                    }
                    else if (resultChar == 'n') {
                        return false;
                    }
                }
            c.format("Please answer 'yes' or 'no'.%n");
            }
        }
    }
 
    private void makeAccusation(int accusation) {
        boolean result = askYesOrNo(String.format("%nIs your number %d? ",
                                                            accusation));
        if (result) {
            c.format("Awesome!%n");
        }
        else {
            c.format("One of us is obviously confused.%n");
        }
    }
 
    public static void main(String[] args) {
        NumberGame ng = new NumberGame();
        ng.playGame();
    }
}

Jan 8 2009

Learning Java – Rot13

I’m planning to do a masters degree in computing in the next year or two. Most of the courses I’ve been looking at are built around Java, so I thought it would be a good idea to learn a bit now when I can relax and take my time. So I’ve been working through the tutorial over the last few days. I’m done with the basics and will shortly be moving on to those essential java classes. So I’m at the point where I can write some little programs to test that I actually do know what’s going on. This fancy book learning is all very well, but I like to get my hands dirty with whatever I’m trying to understand, so I’ll be trying out my knowledge as I go along.

This first program is pretty damn simple. But it’s the first program I’ve ever written in Java, so I’m kind of proud of it. It’s an implementation of the rot13 cipher.:

public class Rot13 {
    static final String ALPHABET = "abcdefghijklmnopqrstuvwxyz";
    private static char rotateChar(char c) {
        if (Character.isLetter(c)) {
            int idx = ALPHABET.indexOf(Character.toLowerCase(c));
            idx += 13;
            if (idx >= 26) {
                idx -= 26;
            }
            char rotatedChar = ALPHABET.charAt(idx);
            if (Character.isUpperCase(c)) {
                return Character.toUpperCase(rotatedChar);
            }
            else {
                return rotatedChar;
            }
        }
        else {
            return c;
        }
    }
 
    public static String rotate(String source) {
        char[] resultArray = new char[source.length()];
        for (int i = 0; i < source.length(); i++) {
            resultArray[i] = rotateChar(source.charAt(i));
        }
        return new String(resultArray);
    }
 
    public static void main(String[] args) {
        for (int i = 0; i < args.length; i++) {
            System.out.println(rotate(args[i]));
        }
    }
}

This stuff is easier in Python, where I’d write something like:

import string, sys
transtable = string.maketrans(string.ascii_letters,
                 string.ascii_lowercase[13:] +
                 string.ascii_lowercase[:13] +
                 string.ascii_uppercase[13:] +
                 string.ascii_uppercase[:13])
for arg in sys.argv[1:]:
    print string.translate(arg, transtable)

Actually, I could write it on one line using less than 200 characters. Not that this is a good idea, but...

import string as s;import sys;a=s.ascii_lowercase;
b=s.ascii_uppercase;[sys.stdout.write(s.translate(
arg,s.maketrans(s.ascii_letters,a[13:]+a[:13]+
b[13:]+b[:13]))+"\n") for arg in sys.argv[1:]]

So yeah, Java does seems a bit verbose at the moment.


Jan 8 2009

Review: Bad Science by Ben Goldacre

The greatest tragedy about Ben Goldacre’s book Bad Science is that the people who need to read it the most won’t. It’s a sustained argument against nonsense masquerading as science, but as Goldacre himself says: “You cannot reason people out of positions they didn’t reason themselves into.” And this is an eminently reasonable book.

I like science. I’m not a scientist, but I like to think that I understand it pretty well for a non-scientist. Most of what gets taken for science is actually engineering. The Large Hadron Collider? Engineering. The space programme? Engineering. It’s the process of ideas being tested that give us the ability to build things like the LHC and space rockets and mobile phones and medicines. Science is essentially the set of methods we’ve developed over the last thousand or so years to test ideas rigourously. Humans are easily fooled and science is the best way we know how to not decieve ourselves.

Goldacre uses subjects like homoeopathy and nutritionists to demonstrate the many ways in which people fool themselves and fool others. He effectively takes apart the claims of homoeopaths and nutritionists like Gillian McKeith as a demonstration of how such claims can be taken apart. In other words, it’s a training manual to spot this kind of nonsense-presented-as-fact and argue against it effectively. It’s the exact reverse of these self-appointed authorities’ intent – Goldacre is trying to empower the reader, not deceive them. Because Goldacre’s background is in medicine, his examples are exclusively health related, but health is the field of science that most directly impacts people’s lives.

This is really only one of two threads that the book is weaved from; the other is a critique of the media’s tacit role in the acceptance and promotion of nonsense, the misrepresentation and dumbing down of science in public life. See, for example, Language Log‘s many posts about the poor science reporting of the BBC, and Goldacre’s own blog for many, many examples. This culminates in an analysis of the 9 year MMR vaccine debacle, where British media – and especially British newspapers – waged a campaign against the MMR vaccine as a cause of autism for the best part of nine years, on the basis of very little and very poor evidence.

Goldacre doesn’t take an entirely uncritical view of science. He draws attention to the ways that scientists have screwed up, making the wrong decisions. He also examines the way that science is sometimes distorted by powerful financial interests. The point is that these are things that scientists have fixed or want to fix, whereas the promoters of nonsense have no such desire.

Much of the material has its roots in Goldacre’s Guardian column of the same name, but it’s more of a distillation of it than a compilation. In many ways it’s a manifesto. Bad Science is one of the best science books I’ve ever read. It’s stunningly relevant, clearly written and often funny – although as a humanities graduate, I’m not entirely sure that Goldacre’s ire against humanities graduates is entirely warranted. Nevertheless, it explains what science is and why it does it far more clearly than any science lesson or textbook. It’s important stuff. If you know why homoeopathy and vitamin pills and detox are bad things then you should read this book to better understand the extent of the problem. And if you take homoeopathic remedies and your multivitamins and follow a detox plan twice a year, you should read it to understand why you’re wrong.


Jan 3 2009

Review: Fear and Loathing in Las Vegas by Hunter S. Thompson

It took me a while to work out that Raoul Duke the antihero and authorial alias of Fear and Loathing in Las Vegas wasn’t really intended as a role model. Some kids want to be footballers, some want to be commandos. When I was a teenager, the drug-fueled excesses of Fear and Loathing were the only model of machismo that I could really believe in. But unless you’re as undeniably talented and charismatic as Thompson was – and I never was – behaving like a drunk, drugged madman is neither entertaining nor endearing. It takes all of Thompson’s skills as a writer to transform his train-wreck Las Vegas tales into the riveting and engaging story it is. It has a wild, unhinged machismo that tendsto strike a chord in the male psyche.

As I’ve got older, reading Fear and Loathing has become less comfortable. It’s very definitely a product of early 70s America, and Nixon, though only mentioned a couple of times, hangs over the book like a bad hangover. Thompson makes a persausive case that the only way to cope with the failure the liberalism of the 1960s was to engage in such excess that it wouldn’t hurt any more. At its heart there’s a deep despair, one that’s still be relevant today.

It’s not quite as fun to read now, though the dazzling acrobatics of its prose is still enjoyable if you can ignore the legions of journalists who have tried (and failed) to imitate it.

Panic. It crept up my spine like the first rising vibes of an acid frenzy. All these horrible realities began to dawn on me: Here I was all alone in Las Vegas with this goddamn incredibly expensive car, completely twisted on drugs, no attorney, no cash, no story for the magazine – and on top of everything else I had a gigantic goddamn hotel bill to deal with. We had ordered everything into that room that human hands could carry – including about six hundred bars of translucent Neutrogena soap.