Professor Daniel Bernstein, amongst others, believes that writing bug free code is possible. I read an article recently about the programs that run the Space Shuttle: aparrently each line of code has had many, many man hours of review and thought put into it.
Aaron Swartz, a student of Bernstein's method, confirms that spending time on code thinking about all possibilities of what can go wrong and what, is a significant factor, but adds that a) method, and b) ability also have a part. Method is related to the fact that some programming practices definitely make writing better code easier, especially the level of abstraction that has been the major progress made in programming languages, exemplified by the build from assembly code to object orientation and now prototypes.
When you WriteMetacode, describing what you want to do rather than the process, that makes the user level narrative apparent where otherwise it would be lost.
But, as Aaron says, one must also have a faculty for writing good code. If you don't have any aptitude for writing code at all, then you obviously can't write bug free code; and likewise if you can code but you can't think very logically, then your code will be bad. By following good methods, practicing, and getting extensive review, you can hopefully get rid of as many bugs as possible, but to get to the 100% level of removal of bugs seems as though it probably requires talent too.
Notes & related:
- WriteMetacode