What is the best style of naming variables in competetive programming and why?. I use long names for variables but i think it is making my code longer and harder to read.
And also it takes often really long time to make a good variable name :D
№ | Пользователь | Рейтинг |
---|---|---|
1 | tourist | 3993 |
2 | jiangly | 3743 |
3 | orzdevinwang | 3707 |
4 | Radewoosh | 3627 |
5 | jqdai0815 | 3620 |
6 | Benq | 3564 |
7 | Kevin114514 | 3443 |
8 | ksun48 | 3434 |
9 | Rewinding | 3397 |
10 | Um_nik | 3396 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
3 | atcoder_official | 162 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 155 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
10 | djm03178 | 152 |
What is the best style of naming variables in competetive programming and why?. I use long names for variables but i think it is making my code longer and harder to read.
And also it takes often really long time to make a good variable name :D
Название |
---|
In programming contests, I try to use something short but descriptive, like str instead of s for a String. It pays off when you have a lot of variables since you can spend a lot of time reading your own code or even get the code wrong when the variables have no meaning at all.
When you are not in a hurry (not in a short programming contest) it's always better to use very descriptive variables and methods, e.g., addUndirectedEdge(int from, int to, int weight).
I generally use small and descriptive variable names like Czechoslovakia,Presbyterian,bureaucratic__ etc
That's not what your submissions say
I know sir,just lightening the mood :) Why so serious :) :)
there should always be some darkness
lightening not lightning :) :)
lightning = (thunder comes with it)
lightening = (making it weight lower) (making something lighter)
am i not right?
True sir. :)
yep then what i said was completely correct
I prefer to avoid simiar variable names. In a problem I denoted a 2-D array with
int ar[100][100];
and I needed a variable to store areaint area;
at the end I had to print area so I just wrotecout<<ar<<endl;
I was surprised by what was printed on the screen (address of the array I think), reading the source 3-4 times revealed the silly mistake.I use very short variable names, usually only one character, but I always use the same variables, so I don't get confused. For example...
Besides, local variables use small letters, global variables have only the first letter in capital and constants/defines use all capital letters.
Always "speaking" variables names. Usually except for one-two sign names, with their default meanings:
a -- array, number
b -- balance, second array, second number
c -- char, count, capacity...
d -- dp, distance, double, second char
e -- edge, epsilon
f -- flag, float, function, first
g -- graph, next function
h -- height
i -- no comments :)
j -- no comments :)
k -- no comments :) + count of elements, more often number-boundary
l -- left, low...
m -- count of edges, count of second array and something else, map, median, matrix
n -- count of anything
o -- not used
p -- prime, prev, point
q -- query, queue, variable like placeholder, second point
r -- right, radius
s -- string, sum, set
t -- time, test, tree
u -- vertex from
v -- vertex to, vector, value
w -- width, weight, third vertex
x -- number, coordinate
y -- x
z -- y
And function names (except maybe f, g, but usually they are in problem statement and dfs0 dfs1 ... dfsN) areAlwaysTellingWhatTheyDoInJavaStyle()
I'm using Java Style usually if code is quite big and that's impossible to use such names as x, y, s, N, M and so on. It means fullDescriptionOfWhatFunctionDoes (type firstDescriptionOfFirstArgument, type fullDescriptionOfSecondArgument...) and some other things. It's quite comfortable for me cuz I'm typing with all 10 fingers and VS usually autocompletes it.