Answer the question
In order to leave comments, you need to log in
Is a separate named method needed if it is used in one place?
Two sides of the issue: writing large methods is bad, i.e. a large sheet of code needs to be broken into small methods. But what if these individual methods are only used in one place? In my opinion, this worsens the readability of the code, complicates debugging, but making huge methods for 100 or more lines in the class also does not contribute to subsequent support. How to act in such cases? Break everything into small methods that will be used only once in one larger one, or do huge ones with large pieces of code?
Answer the question
In order to leave comments, you need to log in
Connect the head, and break. So that logically complete methods are obtained, which can be used in other places if necessary. Even if it's not needed, it should make the code easier to read and maintain.
Make small methods with meaningful names. You get good, self-documented code.
Otherwise, everything will end with the god-method.
the method must be introduced when it implements some change in the state of the object, or to obtain some property of the object. when it is a complete structural unit.
one should not produce new entities unnecessarily.
ps Of course, if the complexity of the method is such that the whole thing does not fit in the head, then you need to break it, otherwise you won't do it anyway. But this doesn't happen as often as I think.
Do not mind it.
If you have such a question, then you still do not understand why such recommendations are given.
That's when you walk through all the rakes, then there will be no questions.
In the meantime, write as you please.
<:o)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question