Write prototypes in a language that you don't use in production.
It allows you to get to grips with the problem and prevents you from just copy-and-pasting large chunks of the "i'll rewrite this later" code into production.
I tend to write my prototypes in Perl as I used to use it a lot in the past for hacking things together. It translates well both to Ruby on Rails (front end) and to C (with low level server magic).