Write Concise Methods
do-write-concise-methods · always_apply: yes
Content
Rule: Write Concise Methods
When designing new methods:
- Ensure the top-level (public) method is concise—ideally 20–30 lines maximum.
- Move all supporting logic and details into well-named private (or inner/helper) methods.
- The top-level method should clearly express the main workflow, delegating specifics to lower-level helpers.
Example:
class SomeObject:
def main_method(self, id):
# Inner/helper method for a single, focused operation
def _short_method(arg):
return op(arg)
target = self._get_target(_short_method(id))
result = self._do_magic_on(target)
return result
def _get_target(self, id):
# Implementation here
pass
def _do_magic_on(self, target):
# Implementation here
pass
Guidelines:
- Keep the top-level method readable and high-level—think of it as a summary of the operation.
- Each helper/private method should do one thing and have a clear, descriptive name.
- Avoid cramming complex logic into the top-level method; instead, encapsulate details in private helpers.
Details
- Slug:
do-write-concise-methods- Always apply:
- Yes
- Created:
- Apr 20, 2026
- Updated:
- Apr 20, 2026
Playbook
Activities 0
No activities linked.