+ 14
I would recommend the following-
1) never name a variable starting with an underscore because it is a practice that is not encouraged.
Eg- int _count
2) if you have decided of a 1 word variable than go for lower case.
Eg- int count
3) if you have decided of a 2 word variable than go for camel case.
Eg- int loopCount
4) if it is a variable that holds a Boolean value than you can use either lower or camel case.
Eg- bool flag or bool isPrime
5) also avoid using a single character as a variable name unless it is used for a loop or something.
Eg- int i
Try to avoid underscore if not necessary but it could be used to differentiate a particular type of variables.
+ 5
Don't forget to mention which language you are using ;)
Naming variables is a sensitive topic. For example in Python language :
a = 1 // Standard variable
_a = 1 // Protected variable
__a = 1 // Private variable
Not all languages adopt this syntax. Mostly the "_" is a decoration for yourself or a code between you and your teammates to clearly notify the type of variable.
+ 2
I rarely name my variables with "2" or "_" (except using Python).
I prefer to use comprehensible names.
I had a student working with me, he used to name is variables :
param1 = 12;
param2= 1;
param3=20;
and the most terrible is that sometimes he reused some of them to set a totally different type of value, such as : param1="Hello";
Personnally I use things like :
userName = "Manav";
userGender = "Male";
userId = 1;
logLevel = [ "Error", "Info" ];
+ 1
Manav Roy
I actually don't know if it's convenient enough because this is not my syntax style.
Here is an example from a true piece of code I wrote using Shell language :
# Paths definitions
in_folder="original/"
out_folder="donnees/"
out_web_folder="web/"
output_memetype="jpg"
# Document informations
original_dpi=300
width=115 # mm
height=192 # mm
left_bleed=10 # mm
top_bleed=10 # mm
page_range=0 # Count from 0 for page 1
+ 1
Shell
+ 1
See Manav Roy, as I said, naming variables "is a sensitive topic", you received many answers. It has differents "religions" :D
The most important is, if the language doesn't request a specific variable syntax, to keep your code understandable for you after few days, weeks, you didn't work on your code, and for others that might work on your code.
+ 1
You have to use an underscore ina variable name to show that there is space between the two words. I am 100 per cent sure of that in Python. For example:
var tech_geek = true
And for python:
sales_recorded = 10
0
Personal suggestion :
just stick to one naming convention.
The 2 most popular conventions are `one using _ ` & another `one using camelCase`.
Note:- please do not mess up around many conventions just choose one your fav one.
0
A lot of good arguments have been provided but for me the most important one is to name variables in a way that explain what's intended for. One example: instead of 'a' use 'oneFruit'
0
Use lowercase for variable
0
yeah, you can, but never start a variable name with a number
0
You should always use a multi character variable name, underscore can also be tricky especially if you are creating large code, Camel case and code like String Ali1=“Alien”, if you make larger code its good to have names you can easily remember, single characters get tricky and you end up needing more time to search for code
0
It's only depand on yourself bro how you want to use
0
درود مهندس یه سوال همیشه ذهنم رو درگیر کرده که در ترانس چرا وقتی برق ۲۲۰ولت مثبت و منفی به دو سر سیم پیچ داخل ترانس وصل میشه سیم پیچ ذوب نمیشه و اصطلاحن نمیسوزه ولی اگه منفی و مثبت همون برق شهری رو به دو سر سیم هزار متری هم وصل کنیم درجا میسوزه
در اونجا چه اتفاقی میوفته و چرا جریان کمتری کشیده میشه و چرا نمیسوزه
0
Both are convenient
0
How you name a variable is just up to personal preference.
You'll just need to remember how you wrote it case for case and underscore for underscore.
You can say something like
int AttStats
int aTtStAts
int att_stats
The only issue with that is, it'll take you more time with coding because you might have forgot exactly how you just wrote it and have to go find it.
- 1
Follow your language code style / pep
Kotlin -> val userAge = ...
Python -> user_age = ....
- 1
Hi