Methods before Members or Members before Methods?

Discussion in 'Web Design & Coding' started by Complete, Sep 12, 2007.

  1. Complete

    Complete OSNN Addict

    Messages:
    94
    Methods before Members or Members before Methods?

    In a header file, which do you define/declare first. Do you list all your variables before the methods (also known as functions), or do you do it the other way around?

    I always thought that you put the variables first. That was the way I was taught in school. Now I hear that that is wrong and you have to do it the other way. I am told you should list the methods first.
     
  2. albybum

    albybum Penguin Rancher

    Messages:
    280
    Location:
    Elizabethton, TN
    I define private members and private methods first. Then, I define all my public accessor methods. For me, classes are much easier to navigate that way. Attributes are listed before methods on UML class diagrams too.

    Basically, it is just preference. If your development house (or school) has a coding standard, you should follow whatever the standard states.

    The compiler isn't going to care. It will optimize your code. I am not aware of any advantage.
     
  3. X-Istence

    X-Istence * Political User

    Messages:
    6,498
    Location:
    USA
    Public
    Private
    Protected

    Unless I need to have a variable that is protected available for a public function, in which case I tend to do

    Private
    Protected
    Public

    for classes, as for functions vs variables

    variables
    functions