Tips on coding libraries and coding with errors?
I've always struggled coding large amounts of code (lots of helper functions, modules, global variables, etc) because when I make a logical error or find a better way to implement something, I always spend a lot of effort changing the code.  So when I'm coding a lot or libraries, I know I'm gonna make errors, but want a way to handle them gracefully.  What are some tips you guys would give that allows a coder to code as fast as he can, but at the same time, code in a style that allows the coder to easily recode when necessary?

Tips like code organization style, module structure, cool coding tricks, etc?
Specific examples, helpful suggestions, or reference links are all great!

I generally code in javascript, c, and python.

Thanks for the tips!
Tips on coding libraries and coding with errors?
===

I've always struggled coding large amounts of code (lots of helper functions, modules, global variables, etc) because when I make a logical error or find a better way to implement something, I always spend a lot of effort changing the code.  So when I'm coding a lot or libraries, I know I'm gonna make errors, but want a way to handle them gracefully.  What are some tips you guys would give that allows a coder to code as fast as he can, but at the same time, code in a style that allows the coder to easily recode when necessary?

Tips like code organization style, module structure, cool coding tricks, etc?
Specific examples, helpful suggestions, or reference links are all great!

I generally code in javascript, c, and python.

Thanks for the tips!