0

Recently i have switched my company and in my new company following coding standards is a must. During my Tech lead review, i got a review comment that "We should not call private methods within private methods."

So is it a generic practice followed everywhere? What if my private method code size is increasing(for ex more than say 50 or 60 lines), then how can we reduce method size and complexity in such a case.

Defining different functionalities in different methods makes things easier to understand as well but if the above mentioned standard for private methods is followed then what is a possible way to handle method complexity in this case.

Raghav
  • 552
  • 1
  • 9
  • 34
  • 4
    If I were in your place I would start looking for a different job. This sounds like a rule for the sake of making rules, as it has no grounding in good practice. Your doubt about it is well founded. – Jim Garrison Mar 20 '16 at 05:59
  • @JimGarrison Yeah, I wonder what kind of [tin god](http://www.dictionary.com/browse/tin-god) came up with such a rule, and what justification was invented, if any. – Andreas Mar 20 '16 at 06:03
  • I always had my doubts on this rule. May be i should start looking for a new job now :) :D – Raghav Mar 20 '16 at 06:08

1 Answers1

6

No, this is not common practice. I've never heard of such a rule, and I can't think of any reason for it. There is absolutely nothing wrong with calling a private method from another private method.

John Kugelman
  • 349,597
  • 67
  • 533
  • 578
  • Totally agree. Any time you have common code, it should be put into a separate method for reuse, rather than replicating the same logic all over. DRY ([Don't Repeat Yourself](https://en.wikipedia.org/wiki/Don't_repeat_yourself)). You should also split methods that are too large into smaller manageable pieces of well-defined responsibility. Helps clarity and code overview. – Andreas Mar 20 '16 at 05:59