   Naming Standard
  I am currently reading Beginning C++ Game Programming, and looking at different C++ web sites. I was wondering if there is a naming standard when it comes to using types. In the book I am reading, it says to use lowercase letters and then a uppercase letter for the start of the second word. Ex:int = myScore;However, I came across the web page www.XoaX.net that says you should use the Hungarian Notation. Ex:int = iMyScore;I was just wondering if there is a naming standard out there that I should use? I am starting to learn the language and I don't want to start with bad habits.   
  There isn't any real standard out there.  It is fairly common to either use lowercase letters with underscores (i.e. my_variable_name and my_class_name) or what is called CamelCase (i.e. myVariableName and MyClassName).  Use whatever you want, but most importantly be consistent.  If you pick a style, stay with it.  If you decide you don't like that style and want to change, I would suggest either sticking with the old style for the current project, or changing everything in the current project to the new style.As far as Hungarian Notation goes... I hate it.  And this is a time when I really mean "hate."  It just clutters the names.  I can tell myScore is an integer based on how you use it, plus its name tells me what kind of information it holds.  You can use it if you want, but most of the code I see doesn't, and I hate the code that does use it.   ;  C++ lacks a consistent naming convention. Many people feel Hungarian notation is fairly archaic though.The closest thing to a standard convention is the one used in the standard C++ library and Boost libaries and I tend to use the convention used in a language's standard libary: it_looks_like_this.At the end of the day it doesn't matter, any reasonable convention is fine, if you work on a group project you might not even get to keep your convention anyway.   ;  Ugh, hungarian notation is annoying as hell x_x If I recall correctly the whole point for it was just so you could determine the exact type of the variable by just looking at its name. But if you need that to determine its type, then maybe you'd want to rename it because its current name isn't descriptive enough. I mean, what are the chances that something named "my_score" is a bool? =P   ;  A bit related:I personally prefer my syntax this way:void methodA(){if(1 > 0){ //print something}}Yet in books and all over the net everyone else usesvoid methodA(){if(1 > 0){ //print something}}Should I stick to what I am used to or change?Software development is often done in projects so I think I might need to change, but I dont really want to :/EDIT: OK, code doesnt look like what I expected but I hope you get the point.   ;  To be honest, the convention used isn't THAT important. Programmers adapt to it fairly well, the most important thing is consistent convention throughout a project.   ;Quote:Original post by bobjinkShould I stick to what I am used to or change?Software development is often done in projects so I think I might need to change, but I dont really want to :/EDIT: OK, code doesnt look like what I expected but I hope you get the point.Just so you know, you have to use [code] or [source][/source] tags to get nice formatting.  Anyway, I prefer it the way you do it, and that's how the C++ and C# code at my work is done.  The Java code, on the other hand, is done using the second style you showed.  It's fairly common for Java code to use that style (simply because that's the standard Java style, but doing it the other way isn't necessarily wrong), but most C++ and C# code I see uses the style that you and I prefer (the first one).  You may have to change how you do it depending on what project you're working on and what style guidelines they set, but you can always do it how you want to on your own hobby projects.  What matters most is consistency.   ;Quote:Original post by bobjinkA bit related:I personally prefer my syntax this way:void methodA(){if(1 > 0){ //print something}}Yet in books and all over the net everyone else usesvoid methodA(){if(1 > 0){ //print something}}Should I stick to what I am used to or change?Software development is often done in projects so I think I might need to change, but I dont really want to :/EDIT: OK, code doesnt look like what I expected but I hope you get the point.Remember that not all project have the same way of doing things, so even if you change, it's still wrong for some projects :);  Thx for the explanation. It made my day much better knowing I can use my way :)   ;@bobjink:Putting your code in [ source ] [ /source ] tags keeps the formatting.I personally prefer the first way, because it's easier to tell if you missed a bracket.if(something)    doSomething();}vs:if(something){    doSomething();}Hard to notice that you are missing a bracket in the first, and not in the second. They look almost identical.Compare:if(something)    doSomething();}vs:if(something){    doSomething();}The first sticks out as wrong, since, if you are consistent in the way you do things, there should always by a line with nothing but a bracket on it, following a while, if, else, or for. If you missed a bracket, you get a function or variable right up against the if-statement, and you notice it instantly.As for naming schemes, I prefer 'variableName' for instances of variables (including class instances), and 'ClassName' for the names of types such as classes, structs, etc... I also use 'FunctionName' for the names of functions, and '_FunctionName' for private functions of a class. I stole that last one from the Heroes of Allacrost coding standards. [smile]I certainly do not specify the type of the variable in the variable's name. If I can't remember what type it is, I shouldn't be using it in code until I re-familiarize myself with what it is and what it does.   