I do programs for several years.
And now I know from my colleagues my pros and cons:
Pros: I can solve very complex problem
cons: I make overcomplicated solutions for simple tasks.
Now I'm trying to fix my cons and looking for generic principles and guidelines for this question:
When should I create an additional piece of code (a function, a class, a module, whatever). And when I should not.
I've seen an answer from some Python guy: whenever you can, don't create, make it as simple as possible.
Well this is a great advice, but having one big function isn't a good idea too.
The problem for me is that I have a principle when to create a separate function for sure, but I don't have an opposite one (when not create). The principle is:
Create a function when you'll have to copy-paste some code and as a result you'll have duplicated code.
(Why: duplicated code is bad, because you'll forget to fix some of copies when you fix a bug in it, you'll have to create times as many tests as you copy, and the is times more letters to read for your team and yourself later, etc...) This can sound as an example of what kind of answers I'm looking for.
So, how do you decide whenever to create a separate function or just extend an existing one?
Thanks everyone who already answered this question, but please add at least some principles when you should not split function (when you should better keep it as a whole).
Because for now most (all?) the answers here are about only when you should split. And my problem is that I make too many functions, I split too often, as coders tell me, - and this is why my question differs from this one Should I extract specific functionality into a function and why? .