I personally go by the monocre that if it’s something important, it’d be all on one file as not to lose the train of thought when debugging it.
As jumping around between files
tends to break up thought lines
also, the compiler likes it better when there’s layers
DarkAri@lemmy.blahaj.zone 2 days ago
The rule of thumb I use is how likely am I to reuse some part of this code in the future? Also readability. Sometimes I like to just wrap some code in functions to make the code look neater. Other considerations are how often will this function be called? The overhead of calling a function is tiny but if a program is used by millions, everyday for many years, it’s sort of like not littering a bit to make the code a bit more inline. It is kind of nice to be able to mostly see what a piece of code does in a glance other than when it’s just wasteful.
kryptonianCodeMonkey@lemmy.world 2 days ago
Concise readability is usually my goal. Like if I have 12 lines of code with a loop and some nested conditionals that takes a bit of thought to parse, it probably is better to move that to a function with a descriptive name like, “size, depth = get_directory_size_and_depth(filepath)”, that way the function name itself functions as it’s own comment/documentation, and, if you don’t really care about how the size and depth is aggregated, it abstracts that process onto one line of code that the reader can instantly understand without parsing anything. That goes doubly so when the function is generic like get_directory_size_and_depth(filepath) would be, and can be put in its own shared utilities file.