Page 1 of 1

For Beginners in C: Variable Naming Conventionals

PostPosted: Mon Oct 10, 2011 8:42 pm
by EvanBlack
A good idea when you are making your variables is to use common naming conventions such as if you have a constant denote it with a c or use all capital letters.

Code: Select all
//Example:
const int cMyConstantVariable = 20; // but as you can see this one doesn't look as neat as the next one.

const int MYCONSTANTVARIABLE = 20; // Now you know any time you see a variable in all capitals,
                                                         // it's a constant, it doesn't change.


Also, when creating your variables for different areas of your code, you should try to make them easy to figure out where they are, and also keep them from getting tangled up in the compiler.

Code: Select all
//Example:

int g_ThisVariableIsGlobal; //This is a global variable denoted with a g_
                                        // so anytime you see a variable with a g_ tag, its a global one.

int a_MyActorVariable;      // This is a User created actor variable.
                                       // You know it was created by the user for an actor because of the a_

int FunctionVariable;         // Function variables can be left the same,
                                       // they don't require any tags because if you are using the
                                       // other two naming conventions you won't have clashes.
                                       // These variables are only used inside the function
                                       // they were created for.



So what this looks like all together, and even allows using the same name over and over with no clashes, (which is not a good habit btw..)

Code: Select all

const int g_VAR = 20;  //global constant

int g_Var;

void SetVariables( int Var)
{
    Var = g_VAR;
    myActor.a_Var = Var;




Now you can see, even with all the variables having the same name, there is no confusion on which variable is which. You can read it easily and the compiler won't freak out. But you shouldn't name you variables the same thing anyway. It just bad coding habit.

Note: Don't look at my current code, its a nightmare lol.

Re: For Beginners in C: Variable Naming Conventionals

PostPosted: Mon Oct 10, 2011 9:11 pm
by Jagmaster
Good stuff to know. Thank you.

Re: For Beginners in C: Variable Naming Conventionals

PostPosted: Wed Dec 14, 2011 8:57 pm
by CoFFiN6
Wow thanx a lot!!! This helped me

Re: For Beginners in C: Variable Naming Conventionals

PostPosted: Wed Dec 14, 2011 9:07 pm
by Game A Gogo
what I've learned in my programming class is to also use things like i,s,c,d,f to identify the type of variable, for exemple
Code: Select all
int iMyNumber;
float fMyFloat;
double dMyDouble;
char cMyChar;


s would be for strings, but GE doesn't have that library.

Re: For Beginners in C: Variable Naming Conventionals

PostPosted: Wed Dec 14, 2011 9:49 pm
by skydereign
Well you could use s for char arrays, sMyChar/sMyCharArray/sMyString.