Code style: helper function used exclusively by one parent function

Nested functions are not encouraged due to potential performance impacts of captured variables, so I usually define helper functions as standalone functions, which unfortunately makes the code less modular / structured. Nevertheless, is there a standardized way to annotate the intent that the helper function should be exclusively used by one specified parent function?

You could use a let block.

julia> let
           foo_helper(x) = x^2
           global foo(x) = foo_helper(x)
       end
foo (generic function with 1 method)

julia> foo(9)
81
2 Likes

If you pass all the inputs to a nested function as arguments (like you’d need to do for a non-nested helper function anyway), then there won’t be any variables to capture.

1 Like