Re:Should you split that file?
by earthboundkid on Friday December 01, 2023 @05:39PM
(#38493538)
That makes the file backwards because main calls foo which calls bar, so it should be main, foo, bar; not bar, foo, main when you read it.
That order makes sense as well and it has the advantage that you will often see how the leaf functions fit into the overall picture if you see how other functions depend on them. I just prefer some linear order over the alternatives.
I like this approach to organisation because it helps avoid dependency cyles. https://fsharpforfunandprofit.com/posts/cyclic-dependencies/
I once had to try and understand the entirety of a subsection by hopping between files that mutually depend on each other, which was quite confusing. UML diagrams I drew didn't help my understanding but drawing a dependency tree (the functions called that depends on no more are leaves and functions that call other functions are nodes) before I knew of this technique did help.
This does have its disadvantages though so I think it's a good default in some cases but one should be given the choice to break it when needed.