I spend all day writing code so it is not unnatural that I blog about it too. I know drupal has code tags but they still end up changing < and > and most code is full of those. There seems to be loads of solutions but many of them have problems - use of code, pre and xmp tags (not all browsers do the same thing with xmp), substituting < etc for < (too annoying, I wan to just paste my code in). Ginally I found the GeSHI filter
and although it is not perfect it works better (by far) than any of the other solutions I've found.