re: Do you (re)arrange your class methods? Why? VIEW POST


Here's what I do, but not incredibly consistently:

  1. follow the style of the package your in. Usually consistency is better than splitting hairs over the "right" way"
  2. If there's no consistent style established and if a class has only a few private helper functions, I try to keep the private helper methods next to the public methods that use them. Then...
  3. If there's no consistent style and there are many private methods or the private methods are used by several, I eventually put all public methods on top and private methods below.
  4. If things get too hairy, I just let IntelliJ sort it out.

That's for languages like Java that really don't care what order the methods are defined. In languages like C or Javascript that have to have definitions or have hoisting, it's a little more complicated so I usually just define all helper functions first like you have in your example.

code of conduct - report abuse