I wonder whether there are good ways to become a bugless coder. Do I need to build some style. I am mostly interested if the top teams of ICPC train their coding by some specific ways (except participating in contests). Good books (or links) teaching the principles of good coding are welcome.
If you encounter a bug ask yourself a question "Is there an automated way of preventing such bugs in future?" For example adding flags locally could help you discover things which are probably not as they were meant to be (like not returning anything from function with int type) or out of memory reads (which are typically not discovered during execution on small testcases). Worth reading: http://codeforces.me/blog/entry/15547 Of course there are other methods of automated bug prevention not connected to flags.