Jump to content
  • Advertisement

Archived

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

Theses

C/C++ programming style

This topic is 6668 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

i always wondered about function names. it seems its divided amongst some different style BigYes() bigYes() bigyes() reasoning behind each of them?

Share this post


Link to post
Share on other sites
Advertisement
You missed another popular one: big_yes()

I usually use BigYes and start all my variables with a lower case letter followed by uppercase for each word. It doesn''t really matter which you choose, as long as you''re consistent with it.

Share this post


Link to post
Share on other sites
Everything but big_yes is good because you need one less character (not saying big_yes is bad! Of course!). Another thing with using BigYes is to make it look different than the C/C++ RT functions and such and thus being able to seperate your functions from runtime C/C++ functions quickly (and espec. for thrid party readers). Some see it the other way around, however.

I use the BigYes style for functions, class- and struct names (I also have a prefix on them quite often eg. gzVector3f if it''s in a library etc.) and big_yes for variables. It''s just a matter of personal likings.

"Paranoia is the belief in a hidden order behind the visible." - Anonymous

Share this post


Link to post
Share on other sites
Big_Yes() is my preference.

although, big_yes() is kind of cool...no capital letters...a little easier





"NPC's are people too!" --dwarfsoft

"Nazrix is cool." --Nazrix first, then Darkmage

Share this post


Link to post
Share on other sites
I think "big_yes" names don''t just look stupid, but they are impractical, so there. I however also use hungarian notation all over my program and think its a good idea too, it lets you know what a variable is without having to jump to its definition. And according to the function naming, MixedCase by capitalizing the first letter in each word is truly the way to go. I also have a habit of placing acronyms of what module they belong to as well. such as:
DDInit()
DDShutdown()
DSPlay()
FEPutText()

I also believe in underscores by placing them in front of names. For instance, when using objects and functions, I have a hard time declaring variables that fill in member structures without using the actual variable name, so to solve this I place an underscore in front like _NumOfVertices or _NumOfPolygons.

I also never really found too much reasoning in creating variable like m_MyMember or g_MyGlobal. I suppose someday I may actually do that, it seems like a good method of letting other programmers know that you are dealing with member names and global variables.

- Tom

Share this post


Link to post
Share on other sites
olp-fan,
Yeah, if you''re planning on having other programmers looking at your code & working w/ it then those styles are good I suppose...even if it''s an M$ idea

But working on my own, I know what types things are...I''m probably developing bad habbits but oh well




"NPC's are people too!" --dwarfsoft

"Nazrix is cool." --Nazrix first, then Darkmage

Share this post


Link to post
Share on other sites
I use whatever seems reasonable at for the application.
For instance, I might do
putpixel()
fRand().
Generally I use either all upper or lowercase





I came, I saw, I got programmers block.
~V''lion

Share this post


Link to post
Share on other sites
quote:

I place an underscore in front like _NumOfVertices or _NumOfPolygons.

I also never really found too much reasoning in creating variable like m_MyMember or g_MyGlobal



Here''s a reason for you Any name starting with _ followed by another _ or A to Z (so that''s _[A-Z_]) is reserved for the implementation at any scope (e.g. a macro). So you could included a standard header and it''s perfectly legal for it to do "#define _NumOfVertices 10" which will break your code. Personally I use m_ for members, but some people like a trailing underscore.

Share this post


Link to post
Share on other sites
quote:

i always wondered about function names. it seems its divided amongst some different style



If you''re working on your own, you can name functions and variables as you want to and generally do as you wish... Most home programmers do it this way as everybody like to think that their way is best...

...But if you ever want to work for a company which demands high standards and multi-developer projects you''ll be forced to program in a more standardised way...

This usually means the correct use of prefixing, hungarian notation, and standardised function naming:-

In C, function names really need to be prefixed, due to lack of namespaces... Generally people use the ''bigYes()'' format like in OpenGL:- glEnable, glFlush, etc.

When working with namespaced functions in like in C++ however, prefixing function names is generally unnecessary. Logic would dictate that you remove the lower case prefix and end up with mixed case names in ''BigYes()'' style.

I don''t know about anywhere else, but where I work, names which are all lower case represent common/pre-defined library functions like ''strncpy()'' that you''d normally get with the compiler...

As for underscores I don''t know... I only ever use them within constants and enums, I find that underscores in function names make it difficult to tell them apart from my constants

Jans.

Oh, and olp-fan , you say you use hungarian notation throughout and then go and name two variables with underscores and no prefixing, what''s wrong with ''iNumVertices'' or ''iVertexCount''???

-----------------
Janucybermetaltvgothmogbunny

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!