Community discussion forum

Methods before Members or Members before Methods?

  • 2 years ago

    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.

    I know this is all just asthetic. But there must be a set accepted way to do this. What is it?  I mean, if you were looking at some sample/example C++ code, how would you expect to see the header files to be written?

  • 2 years ago

    As my experience, I always see the variables first then functions. It's better, since : The declaration of variables usually take less space of code lines, and you need to know about them(vars) to use them in appropriate functions, if they are at the end, you should scroll down then up, but if they are at the first, you just need to go down!

  • 2 years ago
    All the code I've seen has declared the variables first.  I find this makes it easier to read on the odd occasion when you need to think of the class as a stucture.

    However, allways remember that many companies / lecturers / teachers have their own variations. Only use the common standurds in situations where you have NOT been told any different.

    Hope this helps







Post a reply

Enter your message below

Sign in or Join us (it's free).

Want to stay in touch with what's going on? Follow us on twitter!