Simplify Your Code

Keep your functions small by extracting code fragments into their own functions.  If you have to spend even a small amount of time figuring out what a code fragment does, then it should be extracted into its own function and given a name that describes what it does.  Then when you read it again, the purpose of the code should be obvious.  This will clarify the intention of your code (separate from the implementation), while making it self-documenting, more maintainable, and more testable.