C/C++ programming style
i always wondered about function names. it seems its divided amongst some different style
BigYes()
bigYes()
bigyes()
reasoning behind each of them?
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.
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.
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
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
PleaseDoNotUseMixedCaseFunctionNames. I use the "big_yes" style. I hate MixedCaseNames, they''re stupid
I'm reminded of the day my daughter came in, looked over my shoulder at some Perl 4 code, and said, "What is that, swearing?" - Larry Wall
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
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
Need help? Well, go FAQ yourself. "Just don't look at the hole." -- Unspoken_Magi
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
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
Rock on,- Tom
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
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
Need help? Well, go FAQ yourself. "Just don't look at the hole." -- Unspoken_Magi
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
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
~V'lionBugle4d
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.
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
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement