Use Short Functions
Keep your functions short and focussed. Avoid deep nesting!
This is good advice for any programming language. Complex or deeply nested functions can quickly become confusing and difficult to manage. Instead of nesting multiple levels of logic within a single function, break the logic into smaller, separate functions. This will:
Improve Readability: Short functions allow yourself and others to quickly understand what the function does without digging through complex logic.
Simplify Debugging: Isolating issues is easier when functions are concise and perform a single task.
Encourage Reusability: Short, well-defined functions are often more reusable across different parts of the interface or even across projects - see Libraries.
Example: Writing a Mapping Function