Top Or Bottom?

Started by
37 comments, last by Ectara 9 years, 11 months ago

Ok, so i've seen alot of people write classes diffrent ways. some prefer the interface at the top, and the implementation at the bottom, some prefer it the other way.

i.e: Top:


class Foo{
private:
    int m_Member;
public:
 
    void SetMember(int value);
 
    int GetMember(void);
}:

vs: Bottom:

class Foo{
public:
    void SetMember(int value);
 
    int GetMember(void);
private:
    int m_Member;
};

so, i can understand the point of getting to the interface faster, but personally i like having the variables at the top. anywho, what are your reasons, what do you like?

Check out https://www.facebook.com/LiquidGames for some great games made by me on the Playstation Mobile market.
Advertisement

I'm a bottom man. Public interface first.

"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley

I prefer the public interface at the top of the class, and the private implementation details at the bottom (or preferably in an entirely different file) - I want my focus to be on the interface or I might start abusing my internal knowledge of the implementation. Ideally, my classes should be a black-box. How they work inside shouldn't matter to the user of the class (in the general case).

I like bottoms, too. Also, implementation should be at the end of the file.

I like big bottoms and I cannot lie. Actually, I prefer small bottoms. And I really don't mind the top or the bottom -- if it is clean and consistent I think it is good. If it is all mixed up, const-incorrect, with lots of comment doodles a furious wroth descends upon me and likely to refactor with extreme prejudice ;-)

-Josh

--www.physicaluncertainty.com
--linkedin
--irc.freenode.net#gdnet

Yeah don't want too much doodling above and around the bottom (arse antlers, or tramp stamp comments).

"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley

It’s not really that subjective.

Public always goes on top because when people look at your class they only care about what methods they can call and there is no reason, regardless of personal preference, to make them scroll down random lengths that vary depending on the file to find it.

20 video-game guys live in a house with 1 rainbow-loving girl.

Even though the girl is in charge of stacking all the magazines in a drawer, regardless of her own preference to put her rainbow magazines on top, it is still correct to put the game magazines on top and hers on bottom, since more people actually care about the game magazines.

There are also laws regarding the order of enumerations (first), typedefs/structs (second), and methods (third). Enumerations can’t refer to types or functions/methods. Structures and typedefs can refer to enumerations but not functions/methods. Functions/methods can refer to any of the above.

L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

I expected a very different thread given the title.

I expected a very different thread given the title.

hey, maybe your coding style falls under the same....aspect? =-P

Check out https://www.facebook.com/LiquidGames for some great games made by me on the Playstation Mobile market.
Hmmm... my C# style does not fit into either category neatly.

I do:

- Fields
- Properties
- Constructors
- Methods
- Explicit interface implementations

(I don't sort any of them by access modifier)

This topic is closed to new replies.

Advertisement