Archive for the ‘thinking aloud’ Category

What’s Twitter for?

Wednesday, February 25th, 2009

Discounting the last week, my last blog post was on 24 October, then 3 July, then 18 April. Prior to that I was posting a couple of times a month. So what happened to my blog in 2008?

I started using Twitter.

Twitter has been getting some mainstream press lately, mostly though celebrities using it — especially Stephen Fry and Jonathan Ross. As with any new communication medium people are asking: what exactly is it good for? On the Twitter website the synopsis is: "What are you doing?" Well, that doesn't quite describe how I use it. Here's what I use it for.

I use Twitter for semi-realtime conversations.

It may have started out as "What are you doing?" but really, that's just the starting point. Sometimes you really do say what you're doing and if your friends find it interesting, they can comment on it. And not only what you're doing — what you're reading and thinking too. I made only two "QOTD" blog posts last year because I was using Twitter to point these out instead.

Using TwitterFox, which makes my followings instantly available, it's more immediate than a blog and its comments which you have to dive into a feed reader to follow. It's also more uniform than blogs-with-comments, in the sense that the original message and its replies have the same status — they are both just tweets, whereas a blog post is somehow more important than the comments attached to it.

But at the same time it's less immediate than, say, Milliways, or IM. There was a gaping hole between realtime chat and blogging in terms of immediacy and Twitter fills that gap, which I think is why it's so popular. Nobody really wants to know what you are doing every minute of the day and of course letting them know can be dangerous. But it's for sparking discussion and carrying it on, in a way that's in the present yet not demanding that you pay constant attention.

Static typing and correctness

Wednesday, March 19th, 2008

I've been pointed to a post by Joel Spolsky advocating Hungarian notation so that code that fails to properly sanitise strings "looks wrong".

Here's Joel's example. The idea is that you prefix the names of all string variables and functions returning strings with either "s" or "us" depending on whether they're safe or unsafe respectively. Then assignments that have "s" on one side and "us" on the other just look wrong.

us = UsRequest("name") // ok, both sides start with US
s = UsRequest("name") // bug
usName = us // ok
sName = us // certainly wrong.
sName = SEncode(us) // certainly correct.

Well I can think of one pitfall already. How do you mark whether a function expects safe or unsafe data in a way that makes wrong code look wrong?

us = UsRequest("name") // okay
RandomMangler(s) // okay
RandomMangler(us) // errm... wrong?

If you're using a language that supports it, there is a far better way. (more...)

Unix pipelines vs. lazy evaluation

Sunday, June 3rd, 2007

(In response to Gimbo.)

Speaking of Unix, I have thought that there is a pretty close connection between lazy evaluation and Unix pipelines. On the xmonad home page there’s an example for using dzen that looks like this:


while true ; do
    date +"%H.%M %a %b %d"
    sleep 60
done | dzen2 -ta r -fg ’#a8a3f7’ -bg ’#3f3c6d’


Of course, if that was strictly/eagerly evaluated, dzen would never run, because of the infinite loop. But what actually happens is that the two commands, joined together by a pipe (indicated by the | character), are executed in parallel; the while loop runs date, producing some output, which it writes to a pipe (just a first-in-first-out buffer shared by the two processes); it sleeps for 60 seconds; then it runs date again; sleeps again; …, ad infinitum. Meanwhile, dzen reads its output, until there is none left, then blocks until the loop provides more.

(more…)

QOTD IX

Saturday, February 17th, 2007

The idea that a successful person should be happy has thousands of years of momentum behind it. If I was any good, why didn’t I have the easy confidence winners are supposed to have? But that, I now believe, is like a runner asking “If I’m such a good athlete, why do I feel so tired?” Good runners still get tired; they just get tired at higher speeds.

Paul Graham. An interesting essay, which (indirectly) suggests that the reason why people seem more discontented these days is that more of them do jobs where it’s not possible to know you did the best you could. I already know that manual labour is more “satisfying” in this sense than intellectual labour, so in hindsight this idea seems obvious.

A spot of psychoanalysis

Friday, February 16th, 2007

Sean, your timing is spooky. You always seem to manage to blog about something just after I’ve been thinking about the same things!

I don’t recall ever being in a long-term comfort zone. Even when I was feeling ’comfortable’, it was because I was lazy and indulgent, not making the most of life, so I felt guilty. Is this a good thing? I certainly don’t feel good because of it.

I’m at quite an odd stage in my life right now. The monkey (or id) is telling me to settle down, make long term friends, find happiness. But the other part (in psychoanalytic terms, the ego) recognises that settling down at this stage is a kind of prison, so I know I can’t be truly happy that way.

Milliways and the equivalence of programming languages

Friday, January 26th, 2007

It’s been known since the time of Turing that what’s computable in one reasonably powerful programming language is computable in every other one. As a result, we can say that large classes of programming languages are ‘equivalent’ in the sense that they can emulate each other. However, not all programming languages have natural equivalents of all the others’ features.

This is the idea behind Greenspun’s Tenth Rule:

Any sufficiently complicated C or Fortran program contains an ad hoc, informally-specified, bug-ridden, slow implementation of half of Common Lisp.

The usual corollary is “including Common Lisp”. We could say the same for C: most C compilers are implemented in C and compile themselves. Similarly, the Glasgow Haskell Compiler is written (mostly) in Haskell. Actually, given that C is the implementation language for so many interpreters, it’s easy to see that one could, in principle, write a program in language X by directly creating the abstract syntax tree and passing it to an “evaluate” function, all in C.


(more…)

The essence of functional programming

Friday, January 5th, 2007

Here’s an interesting toy language/Turing tarpit for you: Lazy K.


You may already have seen Unlambda, which is essentially the lambda calculus in programming langauge form. (Actually, as its name suggests, it doesn’t actually have any lambdas – it’s really based on the equivalent SKI combinator calculus.) However, Unlambda is a horrible dirty – ahem, I mean impure functional language because 1) it isn’t lazy and so programs in it can sometimes gratuitously fail to terminate, and 2) it has an exception to the evaluation rules (the d ‘function’) and side effects (the .x function prints the character x). Also, in Unlambda version 1 there is no way to do input.


Lazy K is no easier to write programs in than Unlambda (that’s hardly the point, is it? :). But it solves all these problems: it is lazily evaluated; there are no side effects; and you can do input.


(more…)

Greenspun’s 10th Rule in the modern world

Sunday, December 3rd, 2006

Gimbo, as many of you know, is learning Haskell, and just discovered the power and conciseness of lazy evaluation with a one-line definition of the entire Fibonacci sequence.


You can do a vaguely similar thing in Python. First we have a lazy list class:


class LazyList:
    def __init__(self):
        self._list = []
    def __getitem__(self, key):
        length = len(self._list)
        if key.__class__ == int:
            max = key
        elif key.__class__ == slice:
            max = key.stop
        if max >= length:
            for i in xrange(length-1,max):
                self._list.append(self._gen.next())
        return self._list[key]

To create the actual Fibonacci sequence, we define a subclass:
class FibList(LazyList):
    def __init__(self):
        def fibgen():
            lastfib = 0
            nextfib = 1
            yield lastfib
            yield nextfib
            while True:
                (lastfib, nextfib) = (nextfib, lastfib+nextfib)
                yield nextfib
        LazyList.__init__(self)
        self._gen = fibgen()

Then a “list” (not really a list, but looks like one) of the Fibonacci numbers is
somefibs = FibList()
and we can look up the nth Fibonacci number, and take slices of it:
>>> somefibs[0]
0
>>> somefibs[3]
2
>>> somefibs[0:3]
[0, 1, 1]
>>> somefibs[2:20:4]
[1, 8, 55, 377, 2584]

But of course this isn’t a one-liner. Plus we’ve fallen victim to a variant of Greenspun’s Tenth Rule, substituting “Common Lisp” with “Haskell 98” :)

Using a multiuser blog as a better forum

Friday, September 22nd, 2006

A member of the role-playing society (who shall not be named, though some people reading will know who I am talking about) recently tried to set up a SUCS account for the role-playing society for the purposes of making a forum. I have expressed my opinions of forums before on this blog, and will be referring to them here. I would be interested in setting up a forum for the RP soc, except for my reservations about web forums.

Essentially, my major complaint about web forums is their interface. phpBB will email you to tell you of new posts, but these emails do not contain the post’s content, and I assume they don’t contain appropriate headers to let your email client thread them properly. More critically, however, it’s not possible to post by email. Essentially, to interact with the forum I have to use a web browser, and web browsers are not well suited to content that updates irregularly. I want to do everything – read and post – within my email client. (A cynic would say that what I want is a mailing list. And they’d be right, except that I want people who want a forum to have one of those too.)

(more…)

Any fool can be a wizard

Wednesday, September 20th, 2006

Having received the shocking news that Elsmorian has never heard Tommy, I went back and listened to it again myself. While I was listening I read the Wikipedia article, which says “Townshend’s later interest in synthesizers is foreshadowed by the use of taped sounds played in reverse to give a whistling, chirping sound on ‘Amazing Journey’”. I thought “really? never noticed” and listened to it once more.

It’s funny when you revisit things you’ve listened to casually before and discover new depths. I only even noticed these funny chirpy sounds when I listened to them again just now, while they add a wonderful other-worldliness to the song, reinforcing the idea that it’s all a vision inside Tommy’s head. They sound great even today, but it was only when I realised how fantastic they must have sounded in 1969, when the album was released, that I could appreciate it properly. Bear in mind that I’ve been brought up in a musical culture where synthesisers are mundane (we call digital ones keyboards now) and sounds like that are trivial to create with the audio equivalent of the universal constructor, the waveform editor. I think it’s rather sad that my appreciation of it is jaded by having heard similar sounds hundreds of times before, as just another instrument.


It all reminded me of Terry Pratchett’s remarks about conjuring in his interview with Stephen Briggs in The Discworld Companion (my copy is the second edition), where he explains that he would probably enjoy a Discworld play, with its improvised, amateur special effects, more than a Discworld film, with big-budget CG:


I suppose I’m saying it’s the difference between magical tricks being done by a genuine wizard and by a stage conjuror. The wizard does marvellous things but it’s, well, magic and therefore in a sense mundane. Yawn yawn, he’s produced another damn pigeon, well, that’s magic for you. But when you know it’s being done by a conjuror with a hearing aid and a day job down at the building society, and all achieved by springs and elastic and secret pockets, this makes it much more interesting. Any fool can be a wizard, but you have to be clever to be a conjuror.

I think you can say the same for any look back at past innovations. It’s difficult to appreciate the cleverness of past inventors when the modern man looks at their inventions and shrugs — to him, they’re just a prosaic part of his world, no more amazing than a flint knife would have been to a caveman.