Package structure: where do you expect a new function?

While writing code in a package I try to stick to some general organisational principles to make the structure more predictable (even if its mostly for myself). One of them is the idea of functions doing only one thing which leads to many small functions in a file.

Do you have a preferred / expected order of these in Julia (or in general)?

I usually work with “explanation” order, where new functions are introduced (explained) immediately below the place of introduction:

function top()
    mid1()
    mid2()
end

function mid1()
    low()
end

low() = work()

mid2() = more_work()

You can also have the “build up” order that is reversed - lowest level function on top of the file.

So I am wondering if this is something you think / care about and have preferences?

2 Likes

This is the idiomatic style for Julia.

Personally my preference is bottom to top (low, midX, …), but either is fine, and the best choice may depend on the context. Choose what comes naturally, code clarity is the most important, not the order.