The code should be free of uneccessary elements (use css instead of font tags etc) and free of errors. Whether this affects the ranking is not clear but google has to be able to read the code to index you. Links, good content, well optimised site for your keywords.
Someone did a test here on this recently. However basically yes a website exactly the same as another one, but with better coding will rank higher. However 1 extra keyword in the bad code site will offset the benefit of clean code. So the difference is very small. Brad