variable would be used within a function/method and would probably be local
Variable could be a function or global within a class
VARIABLE would usually be a const or static of some form - generally predefined elsewhere
_variable / _Variable usually internal class stuff
So Variable would be the access point for the internal _variable class definitions
vArIAble, variABLE are just dumb and are sackable offenses :P
In essence (on the surface) they all are the same, but in practice there is a general programming method to naming.
Where this becomes more important is with the following sort of stuff
PageCoreTileNum.Value is far more readable than pagecoretilenum.Value and is easier to read (quickly) than Page_Core_Tile_Num.Value where the _ sort of breaks up the flow
Whereas
KEYPRESS_M
STORM_FOUNTAIN
MOVEMENT_LEFT
becomes easier to read and instantly recognisable as some form of static/const that is pre-defined
There are other notations which have the base type also added. E.G.
fX = float value X
iX = int value X
bX = bool value X
strX =string value of X
Again this sort of use allows someone else to instantly look at the code and know what is going on without resorting to finding header files, etc.
The ide should do the legwork, not the programmer.
I'm in the pro case sensitivity group.
It forces consistency
Its not clear to me. give example of it not forcing consistency plz.
well any case sensitive language that doesn't require the user to explicitly declare variables is just asking for a rash of totally avoidable runtime bugs. What languages are like this?
@ good coding standards
Feel free to have them in a case-insensitive language too. It is up to you to keep conform with them.
use PHP and you are able to use undeclared variables.
use Javascript and undeclared variables are handled as globals.
but i didn't realize how good. Am i really that good?
But making the programmer do the case sensitivity is exactly the wrong implementation of this rational.Yep, most IDE's will auto capitalise keywords such as Cos/Sin if that is how the language works.
Problem with case sensitivity is that you can use the exact same word for different concepts. For example:
MyCar myCar, Mycar, mycar; is valid c++ code. You have declared 3 different variables as class MyCar. As code gets larger and more people work on it, similar variable names like that will crop up. When you read over the code, it gets difficult to figure out which "my car" you are looking at.
on the contrary, as long as the language is case insensitive, it doesn't matter what you do with caps in your words. But if your language is case sensitive, and u are using myCar, Mycar, MyCar, MYCAR, mycar - Then u need to see a doctor.Especially if you have to reread one of your old codes that you have not opened for years, and you have to remind yourself that one name is for this and another name for that, but they are all written with the same letters, but not with the same lowercase / uppercase.
#include <iostream>
using namespace std;
int Wheel = 10;
class MyCar
{
public:
int wheel;
MyCar()
{
Wheel = 5;
}
};
int main()
{
MyCar myCar;
cout << "Wheel = " << Wheel << ", myCar.wheel = " << myCar.wheel << endl;
return 0;
}
Now this example is just a scaled down, bare minimum example of the problem. In reality, this would probably be a much larger project. The global Wheel might be tucked deep inside a sub-header of another header inside a physics library that you imported. The class MyCar would probably have hundreds of fields, defining many properties of the car, with dozens of methods operating on the car.Use this code for an example.
...
Now this example is just a scaled down, bare minimum example of the problem. In reality, this would probably be a much larger project. The global Wheel might be tucked deep inside a sub-header of another header inside a physics library that you imported.
public class MyClass
{
private int variable = 10;
MyClass()
{
// maybe do something
}
void Pointless()
{
MyClass MyClass = new MyClass();
MyClass.variable = 20;
}
}
that plays to my suspicion that at least half of all work in the programming industry is fauxYou can say the same of that with all industries - most use fancy ideas, practices and vocabulary that isn't used by regular public in order to keep those 'untrained' out.
yeah... $fileName versus $filename. I tend to use $filename though I try to use lowerCamelCase for most variable names and UpperCamelCase for functions/class names.
Here at work we use _variableName for all class members as well.
Oh, we use C++ here
"Don't overlegislate naming, but do use a consistent naming convention: There are only two must-dos: a) never use "underhanded names," ones that begin with an underscore or that contain a double underscore;"(p2 , C++ Coding Standards, Herb Sutter and Andrei Alexandrescu).
Me... I like to instantly see what the code is telling me. so I use the following:
methods/functions = CamelCase
local variables = lowerCase
class variables _lowerCase
Class Channel
Method New()
End
Property Stereo:bool()
Return _stereo
Setter( stereo:bool )
_stereo = stereo
End
private
field _stereo:bool = False
End Class
Local myChannel = New Channel
myChannel.Stereo = true
Print myChannel.Stereo
But <WARNING> You must watch the cases and what variables you are dealing with in the properties and setters. otherwise it will all go Pete Tong!
interesting to note that it is 'illegal' in c++ to do it (which is what monkey2 compiles into).As it's 'trans-piled' into c++ you can prepend anything you want for the c++ code. It would be probably end up as something like bb_varname in c++ when the coder used _varname in the monkey code.
mx2 code
field _gameTrigger:int = 400
transpiled code
bbInt m__0gameTrigger=400;