In a module (file) I organize several functions related to a specific domain task. I usually put the function linearly from top to bottom, then compose a functional call on the bottom. Doing so I can easily follow the flow on what's happening.

But when I put in a reusable function, it 'breaks' the pure flow as several functions need to call that same reusable function. How to best organize reusable (hoisted) functions ?

Do you use any visual separation from the regular function of the linear flow of operations ? Do you hoist them on the bottom ? Do you declare them on top of the file ? Do you use a special distinction in their name to differentiate them for non reusable, linear function that are part of the flow of operations ? Are there any best practice for this ?

  • 2
    The answer to all organizational questions is always the same: organize the functions in a way that makes the most sense to you and your team. Jul 11, 2016 at 14:46
  • 1
    The answer to this question will become less important over time as more programmers switch over to using powerful, language-specific IDEs. Who cares where a function is defined if a single keystroke will take you there? Jul 11, 2016 at 16:18
  • @jameslarge: Mapping from a known name to the file defining it if easy. Reasonable grouping of things in a project helps find the pieces you need without knowing their names, but only by their suggested use.
    – 9000
    Jul 11, 2016 at 16:29
  • 1
    How do you organize imported functions? They are also defined not right before use, and actively reused. I would section the source file (with comments or by splitting to several files) so that reused functions that belong to a particular domain are grouped together. If a function is only reused twice, and assuming it's small, I'd keep it right in the flow.
    – 9000
    Jul 11, 2016 at 16:32

1 Answer 1


However your organise it, the important thing is to have a standard. Personally, I like putting them close to the top of the file, directly below public types, and above internal functions, but this layout wouldn't be logical with the one you're already using (which puts a higher level function at the bottom of the file) so perhaps you could try inverting it?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.