DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   C++ (http://www.daniweb.com/forums/forum8.html)
-   -   Methods before Members or Members before Methods? (http://www.daniweb.com/forums/thread89407.html)

complete Sep 12th, 2007 3:13 pm
Methods before Members or Members before Methods?
 
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?

Ancient Dragon Sep 12th, 2007 3:54 pm
Re: Methods before Members or Members before Methods?
 
I've seen it done both ways -- and even seen people mix them. Myself, I prefer listing methods first.

Narue Sep 12th, 2007 5:27 pm
Re: Methods before Members or Members before Methods?
 
>Now I hear that that is wrong and you have to do it the other way.
This is a style issue. If your employer requires it, then their word is law. Otherwise, tell the person who said it was wrong it stuff it and do what you find most comfortable.

>But there must be a set accepted way to do this.
Why? Not everything is black and white. As a programmer you have a slew of options that are all equally good. Just pick one and be consistent with it.

>how would you expect to see the header files to be written?
I would expect them to be written with my style because my style is clearly the best. ;)


All times are GMT -4. The time now is 7:27 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC