I create functions whenever I can. My main concern is readability. Testability is entirely secondary, since a lot of my functions will remain private, and not directly tested.
Some key indicators you need a new function:
You have a one-line comment, it's usually better as a function with good name
You have blocks of code separate by whitespace in a function. Chances are, those blocks do something logical, thus can be separated.
You need to scroll up to the function arguments. Long functions are hard to reason with.
There are several exceptions. If adding a function would make the code more complex, then I tend not to do it. I also use a lot of lambda functions lately, grouping behaviour locally and making use of the same scope.
Thank you for stopping by! I am a full-stack developer that combines the power of entrepreneurship and programming to make the lives of programmers easier.
I create functions whenever I can. My main concern is readability. Testability is entirely secondary, since a lot of my functions will remain private, and not directly tested.
Some key indicators you need a new function:
There are several exceptions. If adding a function would make the code more complex, then I tend not to do it. I also use a lot of lambda functions lately, grouping behaviour locally and making use of the same scope.
Are comments a rarity in your projects? Also, do you work on a team or alone?