We are designing coding standards, and are having disagreements as to if it is ever appropriate to break code out into separate functions within a class, when those functions will only ever be called once. For instance:f1(){   f2();     f4();}f2(){    f3()    // Logic here}f3(){   // Logic here}f4(){   // Logic here}versus:f1(){   // Logic here   // Logic here   // Logic here}Some argue that it is simpler to read when you break up a large function using separate single-use sub functions. However, when reading code for the first time, I find it tedious to follow the logic chains and optimize the system as a whole. Are there any rules typically applied to this sort of function layout?Please note that unlike other questions, I am asking for the best set of conditions to differentiate allowable and non-allowable uses of single call functions, not just if they are allowed.
When is it appropriate to make a separate function when there will only ever be a single call to said function?
programming practices;coding style;coding standards
The rationale behind splitting functions is not how many times they will be called, it's keeping them small and preventing them from doing several different things.Bob Martin's book Clean Code gives good guidelines on when to split a function:Functions should be small; how small? See the bullet bellow.Functions should do only one thing.So if the function is several screens long, split it. If the function does several things, split it.If the function is made of sequential steps aimed to a final result, then no need to split it, even if it's relatively long. But if the functions does one thing, then another, then another and then another, with conditions, logically separated blocks, etc., it should be split. As a result of that logic, functions should be usually small.If f1() does authentication, f2() parses input into smaller parts, if f3() makes calculations, and f4() logs or persist results, then they obviously should be separated, even when every one of them will be called just once.That way you can refactor and test them separately, besides the added advantage of being easier to read.On the other hand if all the function does is:a=a+1;a=a/2;a=a^2b=0.0001;c=a*b/c;return c;then there is no need to split it, even when the sequence of steps is long.