My assertion is that in C we (the majority of educated
programmers of today) prefer short functions. I do not wish
to make any assertion about whether this holds or does not
hold for any other language.
I prefer functions not to be "unnecessarily long".
Sometimes "necessarily long" can mean a thousand lines or more.
If a large function is broken up into a small top function which calls many
smaller ones, but those smaller ones have no caller other than the top
function, then the change is pretty much a waste of effort.
Not only that, but C has poor support for dividing logic into functions.
Breaking up a large function into smaller ones can mean changing the structure
of the code in order to simulate the environment passing that naturally occurs
in a language with nested functions. What were originally nice, local
variables in the original function turn into some ugly structure or structures
that only exists in order to support the fragmentation of the logic into
multiple functions. These can harm the performance of the function, and also
trade back some of the maintainbility improvement arising from the breakup.
So, it is perfectly okay for some complicated, self-contained piece of logic
which offers no re-usable small pieces to any other part of the program to be
be represented as a big function that works with a bunch of local variables.
Breaking up logic into functions should only be done when:
- some of those functions will be called from more than one place, eliminating
repetitions.
- some of those functions are useful on their own and will end up being
called by other functions or modules.
- pieces of the original large code were being selectively dispatched by
a large switch or if/else ladder, so that when the function is broken up,
a dispatch based on function pointer indirection can streamline the flow
and possibly even be faster.
Experienced, mature programmers can handle large functions, and large functions
occur in all advanced, real-world projects.
For instance, the function _dl_map_object_from_fd in the glibc dynamic linker:
https://sourceware.org/git/?p=glibc.git;a=blob;f=elf/dl-load.c
goes from line 919 to 1623. (Commit 9455df...bef85a).
People always wish that the world conform to their own physical and
intellectual limitations. Grapes that are out of reach must be sour,
thought the Fox.
Maybe the real principle here is "small functions for small minds".