3 ms·
The ML (metalanguage) family of languages like Standard ML, F# and OCaml intentionally enforce a one-way-flow where a function at the top cannot call anything b
by zogrodea 3y ago
The ML (metalanguage) family of languages like Standard ML, F# and OCaml intentionally enforce a one-way-flow where a function at the top cannot call anything below it (although there are ways to get around it).
I like this approach to organisation because it helps avoid dependency cyles.
https://fsharpforfunandprofit.com/posts/cyclic-dependencies/ 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.
- earthboundkid 3y agoThat 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.
- zogrodea 3y agoThat 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.