I feel like this is just an OOP way of thinking about stuff maybe, but I find that the process of breaking that 9 line method into 2 or 3 methods actually creates an additional layer of complexity, even if it turns out that there could be a benefit.
Sure there are cases where you should slim down large functions, but anything greater than 8 lines of code isn’t at all guaranteed to be bad.
I would also appreciate an expert’s opinion on this question. I am not one. Did you watch the alpha course’s video on refactoring? It comes down to making sure each method only does one thing. Technicalities aside, it’s like a thesis statement in an essay. If the thesis is too long, it’s doesn’t get the point across. I think that’s why methods are short.
Yeah I can agree that you don’t want any one function or method doing too many things. I think sometimes if you religiously follow this whole ‘never let a method do more than one thing’ principle it can lead to over abstraction.
My friend wrote this function to find the differences between two objects, maybe this code isn’t 100% perfect, but the function itself is incredibly simple and it would only complicate a simple function to try and make sure it isn’t any longer than 8 lines.
Sure one could make 3 functions ‘added’, ‘removed’, and ‘change’ and pull them out so that the main function is only a few lines long, but that is just separating out pieces of code that don’t need to be separated, it isn’t adding any value to the code.