Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

timm

Cdong Standards.

This topic is 5930 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Is it best to name my classes like: myClass, or theClass, or aClass. How do the windows game programming gurus do it?

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
Every variable should be my*something*. I love grading student code that is my this and that, it rules.

Share this post


Link to post
Share on other sites
quote:
Original post by timm
How do the windows game programming gurus do it?


I don''t think LaMonthe does C++, so he wouldn''t have any class names.

You should the naming scheme that matches what you are coding. If you''re working with/making extentions for the STL, everything should be lowercase_and_have_underscores; if you''re doing m_mfcProgramming, you should use scope warts and camelCase. If you''re doing ICOMInterface programming, then CConcreteClasses should be used.

The only place I have ever seen mySomething used is in textbooks or maybe articles as rhetorical examples of where you put your class declaration.

Recently I was convinced that explicitly stating the C++ scope access was better than using scope warts, and after trying it I like it better:
this->member_variable (instead of m_member_variable)
Class::static_property_or_method
::global
local


Magmai Kai Holmlor

"Oh, like you''ve never written buggy code" - Lee

[Look for information | GDNet Start Here | GDNet Search Tool | GDNet FAQ | MSDN RTF[L] | SGI STL Docs | STFW | Asking Smart Questions ]

[Free C++ Libraries | Boost | ACE | Loki | MTL | Blitz++ ]

Shamelessly ripped from Oluseyi

Share this post


Link to post
Share on other sites
quote:
Original post by Magmai Kai Holmlor
You should the naming scheme that matches what you are coding. If you''re working with/making extentions for the STL, everything should be lowercase_and_have_underscores; if you''re doing m_mfcProgramming, you should use scope warts and camelCase. If you''re doing ICOMInterface programming, then CConcreteClasses should be used.



And what if your program uses STL, MFC, COM, and other libraries at the same time? With all those mixed naming conventions used right next to each other it''s going to get very confusing, IMO.

I dunno, right now I''m still of the opinion of writing wrapper classes (using composition) for all external library classes.

Doing this lets you use one naming convention throughout your program, allows you to add free extra functionality to each wrapper class without affecting your program, and allows you to even switch library implementations behind the scenes without affecting code already written.

Still, it sucks to rewrite all the public functions for every class you use, but I still feel this is the best way to go about it.

As for my, a, the, I use scope warts instead. I''m undecided on explicitely stating the C++ scope access as Magmai is doing. It''s a lot more typing, but it is easier to read I guess... gotta think more about this


- Houdini

Share this post


Link to post
Share on other sites
It doesn''t matter what your naming scheme is so much as that you use it consistently.

I personally detest the *my* is myWhatever. Other people like it. It doesn''t matter a whole lot really.

-Mike

Share this post


Link to post
Share on other sites
I like the my for class member because it gives a prefix to member variable and I find it easier to read than m_.

Seems like my brain has trouble to read underscores and slows me down a lot, so with my, stuff is more fluent.

Share this post


Link to post
Share on other sites
I agree with Magmai to an extent. All my class members and local variables use MixedCase, and I write class names like CVector or CPlayer. I rarely use global variables, but when I do, especially within classes, they are prefixed with a global scope resolver ::LikeThis. I find that having a single convention of case and spacing across all constructs (Functions, VariableNames, etc) helps me; it just looks pretty.
I don''t like myMemberName, because camel casing is really distracting, especially when I have more than one word in the identifier name, like myGunName. Ugly. I use naked pointers instead of std::vector for everything that needs to be in an array, and array names are usually ended with "List," as in EntityList. The only other indicator of type that I use is for some boolean values, which are prefixed by "Is," as in IsAlive.

That''s just about everything about my wacky coding style.

Peace,
ZE.

//email me.//zealouselixir software.//msdn.//n00biez.//
miscellaneous links

[if you have a link proposal, email me.]

Share this post


Link to post
Share on other sites
quote:
Original post by timm
How do the windows game programming gurus do it?

However it damn well pleases them, of course! Seriously, though, if you are working on your own project then choose something you like and be consistent about it. If you are working on someone else''s project, chances are it''s not your problem. The only thing to beware of is that a coding standard should not restrict expressivity - i.e. it should only contain stylistic guidelines.


[C++ FAQ Lite | ACCU | Boost | Stroustrup on Learning C++]

Share this post


Link to post
Share on other sites
The way I do things is by putting "m_" before the variable name.
for instance:

class CExample
{
public:
float m_fFloatNumber;
};

I see most people do this, however this is just from my experience. using "my" is kind of used for beginners as they grasp ownership concepts in using classes.

Share this post


Link to post
Share on other sites
quote:
Original post by Gorg
I like the my for class member because it gives a prefix to member variable and I find it easier to read than m_.

Seems like my brain has trouble to read underscores and slows me down a lot, so with my, stuff is more fluent.


Being the company''s coding standard doesnt hurt either.


University is a fountain of knowledge, and students go there to drink.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!