Home Structuring methods

Use methods to organize your code

Besides using methods to help reduce redundancy, you should also use methods to help structure and organize your code into distinct sections to enhance readability.

A good rule of thumb is to try and write methods that contain a single primary responsibility. Try and avoid trying to do too many things at once: use helper methods to divide and delegate subproblems.

Main methods are a summary

Your main method should be a summary of your entire program – like a table of contents. This is an extension of the previous rule.

Trivial methods

Never write a method that does only a single operation or is composed of only a single component. Instead, just perform that operation directly and skip the middle-man.