A method or function normally contains the following logical sections:

  • Initialization (assertions, validation of input variables)

  • Processing

  • Cleanup and return

Poorly structured code tends to check for valid parameters in varied places and do disjointed processing without a clear flow.  Such code also returns values from anywhere, and cleanup occurs in unpredictable locations.  

Exception: This is a recommended method structure to be applied if no plan exists.  If there is a compelling reason to use another structure, use it.

blog comments powered by Disqus