Older blog entries for mwh (starting at number 102)

Bram: A little criticism of your rational class:
    def __add__(self, other):
        if type(other) in (int, long):
            return rational(self.num + other * self.den, self.den)
        return rational(self.num * other.den + other.num * self.den,
            self.den * other.den)
If you're using Python 2.2 (or later), you'd be better writing the "type(other) in (int, long)" as "isinstance(other, (int, long))".

Assuming an operand that isn't an integer or a long is a rational is going to lead to some wierd tracebacks, I'd have thought.

Finally:

    def __init__(self, num, den=1):
would seem to be a win, from here.

You didn't say you wanted criticism, but you got it anyway :)

Last week was spent hiking in Spain. Climbed the highest mountain on the mainland (3482m of Mulhacen) and various other lumps. Did not think about computers or mathematics once. Had fun.

However, I'm developing a serious hatred of travelling by air. It's a combination of the seemingly endless hanging around and the relentless patronization that gets me, I think.

In hacking news, helping to get Python 2.2.2 out the door.

The slow pace of recentlog conversations is kind of refreshing. You actually have a chance to think about what you're going to say...

raph points me to the GC FAQ, which taught me a few things, but still left me with the impression that for all it's flaws, the "refcounts + smarts" GC Python currently uses is still about the best choice given the constraints.

You also say:

I haven't done benchmarking, but my intuition tells me that Python's approach is one of the poorest performing.
Uhh, then sorry, you lose. I've been surprised by flukes of compiler optimisation, cache behaviour, etc too many times now to believe anything about performance -- sometimes even with benchmarks to back them up.

One point to mention:

For four, I'm sure that Python's cycle detector is slower than most mark-sweep collectors, because of all the extra accounting it has to do.
Yes, but it doesn't have to run at all often. If mark & sweep is all you've got, then it matters more. For allocating and deallocating in a tight loop rc is actually quite nice; you get to reuse the same memory over and over.
Recentlog
raph confuses me with terminology:
Python 1 is reference counted only, and Python 2 adds garbage collection.
Now, to me, reference counting is a form of garbage collection -- a particularly conservative one, with obvious flaws, but still a gc.

Python 2 added cycle detection to the reference counting gc, eliminating the most obvious flaw of reference counting.

The cycle detector crucially depends on the reference counts to determine when a bunch of objects are an unreachable cycle.

Then:

Garbage collection is often faster, largely because you don't have the overhead of constantly bumping the reference count.
Here I guess garbage collection means mark and sweep or some kind of generational collector.

IMHO the worst problem remaining with the "reference counting + smarts" gc as in Python 2.x is that you need to fiddle a reference count (and so haul an object into the cache) just in order to forget a reference.

I'd guess reference counting gives better performance than stop and copy! Unless your program it sufficiently shortlived that it never has to run a gc, of course.

Someone made some comments about typing in Python and ocaml but they've scrolled off recentlog and I can't remember who it was nor think of a sensible way to find out except wait until google indexes his or her diary page.

Anyway, they said something like this:

Ocaml can deduce types in most situations and generate fast code. Python doesn't try to do this, but I hope some one can make it do so.
(apologies for misrepresentation)

I think you'll find that the ocaml designers worked very hard on the type system of ocaml (and probably the whole language) to make this possible. It's not just a matter of clever implementation. IOW, I don't think it's possible to reverse graft this onto Python with it's ad hoc collection of types and interfaces.

I'd be happy to be wrong here, BTW.

9 Sep 2002 (updated 9 Sep 2002 at 12:36 UTC) »
Living on expenses
Have been at a conference on Non-Commutative Geometry and Rings in Almeria in Spain. Was quite good fun, but very knackering. 7 talks a day, which would have been heavy enough on its own, plus staying up late and drinking.

Hard life.

Living with one ear
A few days ago my left ear stopped working as it should. I didn't feel up to explaining this to a Spanish doctor (my spanish is woeful) so I've been mildly "hearing impaired" for a while.

It's bizarre what gets harder and what doesn't. Following a conversation against a noisy background is very much harder, unless I can lip-read. Surprisingly, direction-finding hasn't got much worse, except for certain kinds of sound.

Anyway, seeing my GP tomorrow & hope he can patch me up...

Links
This is funny, if you know the LOTR.

This is very neat. A useful flash object! Wow!

ICFP 2002

The conference meant I missed this (as I always seem to -- I haven't been able to enter it for one reason or another for the last four years). Scanning the task description it looks like a good problem to tackle in Python, and indeed there are a lot of program entries in Python. I wonder how they'll do.
Recentlog
Bram: You say
ZF feels like something which was logically compelling but then had awkward restrictions placed on it to get rid of some paradoxes.
Surely that's precisely what it is? This doesn't strike me as a very deep observation, I'm afraid.

I was briefly interested in logic, but now anytime I end up worrying about my set theory, I take it as a sign I've wandered into the wrong ends of the subject.

Set theoretic worries come up when trying to define derived categories in a general setting, but I think someone else has sorted that out by now :)

Maths
I should have had my end of year report in two days ago. Oops.

Reading some papers on Gromov-Witten invariants. My head hurts.

Hacking
Not much.
Life
Went to see Austin Powers 3 last night. Some bits were very funny. I really liked the intro.
Still liking OS X
Printing from Mac OS X to our department printers turns out to be roughly as complicated as falling off a log. Which is nice.

I haven't paid my Jobs tax yet and moved up to Jaguar; only a matter of time though.

Installed Chimera, which is nice, but slow and crashy. Nostalgia for old mozilla milestones...

Maths
Not much. Going to a conference in Almeria (Andalucia, south Spain) next week. Doing excercises from Hartshorne.
Hacking
Not much of this either. Coping with the fallout of (and minor bugs in) my SET_LINENO removal patch for Python. Moving towards getting pyrepl into publically available CVS and setting up a mailing list, etc.
Life
Well, given that I haven't been doing maths or hacking of late, I must be having an exciting time of it, right? Well, not really, but I did go and see Lee Scratch Perry and Paul van Dyk last week (on separate nights...). I like living in Bristol!

I really need to learn a little Spanish.

15 Aug 2002 (updated 15 Aug 2002 at 15:28 UTC) »

So, does anyone know how to use cdrecord and friends to do cd duplication on mac os x (on an ibook2 w/combi-drive)?

It seems that dev=IODVDServices is part of the necessary magic, but you also have to convince the Finder to leave the disk alone, and that's proving frustrating...

Oh well, I guess there are more appropriate places to ask this question...

In hacking news, my SET_LINENO removal patch to Python got checked in. This must be one of the subtlest pieces of code I've ever written. I'm glad it's done!

6 Aug 2002 (updated 6 Aug 2002 at 14:47 UTC) »

I seem to be doing something I do every few months: spend a week browsing the web solely using a text-mode browser.

Of course, the text-mode browser in question is w3m-img so I'm not being Luddite enough to avoid inline images. No Java or Javascript, though.

I doubt I'll do this forever, but almost every site I've visited has worked fine. Startup time certainly beats the pants off mozilla.

I seem to be going through a re-reading things phase: the name of the rose & Dan Simmons' Hyperion books. It's not as though I don't have huge stacks of books I haven't read.

mathieu: and some people think C++ is a language for writing applications in...

Update: OK, so I had to fire up mozilla to see my name in pink. Ulp.

Another weekend slips by. Not a lot of hacking done.

Currently downloading the realMyst demo to my ibook. Gawds, this is a slow process.

It also looks like the Quicktime 6 update will end my 37 days of uptime.

93 older entries...

New Advogato Features

New HTML Parser: The long-awaited libxml2 based HTML parser code is live. It needs further work but already handles most markup better than the original parser.

Keep up with the latest Advogato features by reading the Advogato status blog.

If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!