DEV Community

Discussion on: How do you decide what order to put code in?

Collapse
 
ben profile image
Ben Halpern

Uncle Bob's clean code dictates that functions within a file should descend based on abstraction layers. So the high level stuff towards the top, and closer to the metal as you go lower in the file. This would mean I wouldn't put the function a function calls right underneath it unless there are no other public or high-level functions that deserve to be higher.

But that's just one take, I'm sure there are competing thoughts and I'd love to read them.

Collapse
 
nektro profile image
Meghan (she/her)

+1 that's the way that makes the most sense to me, though personally I do it backwards to that because imagining I'm the compiler, it makes more sense to put the functions that don't reference any other functions at the beginning, and then to build up down the file.