← Back to context

Comment by eneveu

3 months ago

If you read Clean Code and other similar books, they don't necessarily advise moving the sub-functions to other files, or splitting them arbitrarily. They simply have the top function delegate to sub-functions that are lower in the same file. Even better if these sub-functions can be marked as private in your language (to avoid polluting the public API of your object). And here the goal is to use function names to document what each block of code (sub-function) does.

Example:

    def process_order(order):
        _validate(order)
        _reserve(order)
        _charge(order)
        _confirm(order)
    
    def _validate(order):
        ...
    
    def _reserve(order):
        ...