Reply
Old September 12th, 2007 Top | #1
 
Complete's Avatar
OSNN Addict
Joined: August 2005
Posts: 94
Reputation: 10
Power: 83

Default 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.
Complete is offline   Reply With Quote
Old September 18th, 2007 Top | #2
 
albybum's Avatar
Penguin Rancher
Joined: February 2002
Location: Elizabethton, TN
Posts: 280
Reputation: 180
Power: 129

Default Re: Methods before Members or Members before Methods?

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.
albybum is offline   Reply With Quote
Old September 19th, 2007 Top | #3
 
X-Istence's Avatar
*
Joined: December 2001
Location: USA
Posts: 6,496
Reputation: 2808
Power: 220

Default Re: Methods before Members or Members before Methods?

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
X-Istence is offline   Reply With Quote

Reply

Bookmarks

Thread Tools

Posting Rules

Similar Threads
Thread Thread Starter Forum Replies Last Post
methods for WBXML decoding sachinjain_30 Portable Devices & Gadgets 0 October 5th, 2006 4:17pm
Java Methods PseudoKiller Web Design & Coding 20 March 31st, 2004 2:26am
Backup methods? jkoXP Windows Desktop Systems 5 September 16th, 2003 10:51pm
Other Methods With Ramdisk!?? Hercules Windows Desktop Systems 2 April 13th, 2002 11:13pm