4 ms·
It's true one huge function repeating things and excessive fragmentation into subfunctions are both less than ideal to maintain and there's a desirable middle g
by outsomnia 6y ago
It's true one huge function repeating things and excessive fragmentation into subfunctions are both less than ideal to maintain and there's a desirable middle ground. But
>> Very short functions are a code smell
that's definitely not unconditionally correct. There are many cases where dereference helpers of the form x_to_y(x), wrapping type conversions that might go through three or four levels of struct members are going to eliminate mistakes in bulk code. They may be done as preprocessor defines or as inline functions but either way they are usually a green flag, not a red flag.
- eesmith 6y agoYou quoted the title, but the title isn't the complete conclusion, which is: > As such, software developers should be wary of breaking their code into too small pieces, and actively avoid introducing very short (1-3 lines) functions when given the choice. At the very least unnecessary single-line functions (ie. excluding getters, setters etc.) should be all but banned. I believe a x_to_y(x) fits into the "etc." of acceptable single-line functions.