Wednesday, March 21, 2007

Programmers Can't (part deux)

Wrote this for another conference, but I just can't be bothered any more.

> ISTR the core of a 3D modelling app in the 90s was written in
> assembly.

Shock! Horror! Never! Not the 90s!

Sorry, but this thread is becoming increasingly surreal; it's true enough that most programmers these days are writing non-critical applications for absurdly fast machines and so don't need to care much about efficiency, but there's still plenty of assembler being used where performance and reliability do matter.

For all the exaggerations put about the difference between compiled code from an efficient language (C, for example) and competent assembler is very rarely less than a factor of three (execution time) and can be several orders of magnitude. A sensible rule of thumb is that on average a bloody good compiler will emit code that runs about three times slower than bog-standard human assembler. It's meaningless to discuss the ratios for optimised assembler; it depends too much on specific circumstances. Besides, outside the fevered imagination of other programmers the reality is that assembly programmers very, very rarely bother to optimise their code; bog standard assembler is usually fast enough.

The performance difference between compiled code for an inefficient language, as most are these days, and assembler is correspondingly greater; frankly only a fool would consider them comparable, so I find it fairly disturbing that so many programmers are ignorant enough of the basics to talk about compiled code and human produced assembler without understanding that the two things are really poles apart.

Now, every time the subject comes up on cix it gets bogged down in irrelevancies - "I don't use assembler because it makes the dog throw up", or "It took me five years to write a Hello World program in BASIC, I wouldn't live long enough to do one in assembler", or "I knew someone who knew someone who had a friend who wrote everything in assembler, even love-letters, but they gave up when compilers started producing better code" without mentioning this happened after they'd become so senile they couldn't remember their own name, or whatever, so don't expect me to do more than this one grump. If anyone needs a reality check have a look at some of the compiler code dumps in cix:avr, or cix:zeitgeist/mp3vsassembler:8 where I've looked in some detail at the code emitted by compilers (mainly C/GCC). I might be persuaded to argue the case in mp3vsassembler, I suppose, but frankly I doubt it.

Still, this is a beginners topic, I suppose. Perhaps for our next excursion into profound ignorance we could round up a few virgins and get them discussing sex? I'm sure we could find a few who'd consider themselves Don Juan on the basis of their first fumble; be much more fun to read and maybe more relevant to linux than the ramblings of a few programmers who "saw some assembler once" and believe that makes them experts in computer science. Just a thought...


(cix: August 2006)

No comments:

Post a Comment