| |||
Views: 88,498,945 |
Main | FAQ | Uploader | IRC chat | Radio | Memberlist | Active users | Latest posts | Calendar | Stats | Online users | Search | 04-29-24 02:56 AM |
|
Guest: Register | Login |
0 users currently in Computing | 1 guest |
Main - Computing - Programming Poll #4: Variable Names | New thread | New reply |
Kernal |
| ||
Gone Level: 88 Posts: 383/1881 EXP: 6463564 Next: 187100 Since: 02-20-07 Last post: 6149 days Last view: 6140 days |
When coding, how do you tend to name your variables?
I like names that are short but still descriptive. Like if I was making a game and needed a variable to track the score, I'd call it "score" and not "s" or "numberOfPoints". I like knowing what a variable does by looking at the name but not typing zillions of characters. Function names are generally a bit longer such as "getPercent", but not ridiculously long as in "displayNumberAsPercentage". I do use i and j for loop counters, x and y for Cartesian coordinates, one-letter names for variables in an equation (so if I wrote a quadratic formula function, it'd probably have variables called a, b, and c rather than (say) aValue, bValue, cValue or (worse) secondPowerCoefficient, firstPowerCoefficient, and constantCoefficient), ch for a generic character input from getchar() or similar, and so on. Obviously if I have to differentiate two sets of x and y coordinates, I'd call them like playerX and playerY and then enemyX and enemyY or whatever. And I tend to use really short names in the dopey programs we write for class like "Write a function that takes two numbers and multiplies them together". As for capitalization, sometimes I use all-lowercase and sometimes camelCase depending on the programming language, I tend to make it "blend in" with the built-in function names and such. In OOP languages I use the standard convention of uppercase at the start of a class name, lowercase at the start of a variable or function name, and all-caps for constants (not like I use them very much). In PHP I tend to use all-lowercase. I never use underscores as they're a bit of a pain to type. The thing that drives me nuts that some programmers do is REALLY long variable names, as in: for (numberOfRubberChickensEaten = 0; numberOfRubberChickensEaten <= 10; numberOfRubberChickensEaten++) I mean, sheesh! Do you really need all 27 letters there, especially for a for loop variable, which is almost always repeated at the top of the loop three times? |
Katelyn |
| ||
beh Level: 86 Posts: 479/1816 EXP: 6131204 Next: 10903 Since: 02-21-07 Last post: 6148 days Last view: 6148 days |
I try to refrain from names that are too short or too long, and try to stay around 3-10 characters in variable names. |
blackhole89 |
| ||
The Guardian Moloch whose eyes are a thousand blind windows! Level: 124 Posts: 92/4196 EXP: 21537518 Next: 299083 Since: 02-19-07 From: Ithaca, NY, US Last post: 474 days Last view: 86 days |
|
Xkeeper |
| ||
Level: 105 Posts: 566/2846 EXP: 12030798 Next: 231462 Since: 02-19-07 Last post: 6062 days Last view: 2800 days |
my variable names are borderline unreadable and unintelligible. ____________________ I dealt with it. |
DarkSlaya |
| ||
Cheep-cheep Level: 32 Posts: 36/189 EXP: 205883 Next: 559 Since: 02-19-07 Last post: 6004 days Last view: 5996 days |
Everything tends to be descriptive but short (but wtf, I comment my stuff anyway).
since I do mostly php and mostly boards: my vars are usually named in manner where you get $[first letter of whatever I'm getting][type of data, such as stat or wtf] functions are usually named in twowords: what it does and with what -> loaduser() But I use one letter variables when I'm need to increment something. Like with for() |
Kattwah |
| ||
Fuzzy Level: 60 Posts: 286/778 EXP: 1719538 Next: 53240 Since: 02-19-07 Last post: 2492 days Last view: 1654 days |
Hmmm
I usually use the shortest description of whatever word Im storing. (Eg, counting numbers = count, frequency of something = frequency) Sometimes I do the abbreviation of it (frequency = freq, strength = str, etc) when I have a lot of variables and a lot of typing to do (Also, laziness factor applies) For looping, temp variables are usually i, or the first letter of whatever variable is getting worked in that loop. (IE, Im counting the number of dogs in an array, Id use "d") Method names are standard getWhateverINeedHere(But never this long anyways) It helps to be able to read your code in any case, so thats the philosophy I go by for naming. ____________________ |
Zem |
| ||
Panser DOOM FOR VON DOOM Level: 42 Posts: 30/343 EXP: 503254 Next: 18108 Since: 02-21-07 Last post: 5516 days Last view: 5514 days |
just long enough to be obvious to someone who has never seen my code (which is basically me after a few weeks/months).
usually camel case, all-caps with underscores in the case of constants. the usual. ____________________ |
Sukasa |
| ||
Red Birdo Level: 92 Posts: 64/2112 EXP: 7690999 Next: 65938 Since: 02-19-07 Last post: 4450 days Last view: 3222 days |
depends on how many variable I have. I've written subroutines that use variables a,b,c,...i. All a combination of bytes, longs, and strings
With other code, I've written code that uses variable names like "NumPlayers", "MainCarDataArray()", etc. |
setz |
| ||
Spike fuck~ Level: 58 Posts: 109/722 EXP: 1537227 Next: 40319 Since: 02-19-07 From: Pittsburgh, PA Last post: 5293 days Last view: 2580 days |
Posted by DarkSlaya I think that more or less sums up the same for me. I call variables what the represent relative to whats going on, unless they're temporary ie. counters, then just whatever key I hit first, which is usually i/j/k/l/o/etc. Typically, everything is under case. Alot of people like to tell what type of variable it is, ie. intFaggots, but thats just un-needed typing imo. ____________________ |
Ailure |
| ||
Hats Steam Board2 group Level: 121 Posts: 340/3965 EXP: 19783316 Next: 273380 Since: 02-19-07 From: Sweden, Skåne Last post: 3304 days Last view: 2055 days |
I think I used x, y, z, a, b, c for loops. Happened that I waded through 3D arrays with loops.
I might try using ungarian notation if the group I program later in requires it. It's not however something I'm found off, as most of my variables are self-descriptive and I tend to lean towards a OO design... ____________________ AIM: gamefreak1337, MSN: Emil_sim@spray.se, XMPP: ailure@xmpp.kafuka.org
|
JerryArr |
| ||
Red Cheep-cheep Level: 34 Posts: 8/210 EXP: 240894 Next: 12757 Since: 03-03-07 From: Levittown, PA The former Monarx Last post: 6196 days Last view: 6189 days |
I tend to use...
-Single letters for loops, usually top row keys -Something like "allGood" for booleans that deal with if something is good to go on to the next part -Things like casesLeft for numbers -At times, though, it'll get random. |
Squash Monster |
| |||
Buster Beetle Level: 48 Posts: 31/469 EXP: 804620 Next: 18923 Since: 02-22-07 From: New York Last post: 5699 days Last view: 5699 days |
|
Ninetales |
| ||
Panser Level: 42 Posts: 82/338 EXP: 492390 Next: 28972 Since: 02-19-07 Last post: 5513 days Last view: 4911 days |
Posted by Squash Monster Or at least the way it's taught in programming courses. All of the above applies to me as well, excepting constants that I just do in the same format as normal variables. |
Xkeeper |
| ||
Level: 105 Posts: 619/2846 EXP: 12030798 Next: 231462 Since: 02-19-07 Last post: 6062 days Last view: 2800 days |
Posted by Squash MonsterThere's no "way it should be". That's like saying everyone should use the exact same color scheme. It's called style. ____________________ I dealt with it. |
Xeon |
| ||
Red Paratroopa Level: 31 Posts: 1/174 EXP: 181613 Next: 3750 Since: 03-09-07 Last post: 6022 days Last view: 3224 days |
For Visual Basic I like to use Hungarian notation for almost everything, strData, or sometimes if I'm feeling lazy that day ill use 1 character type prefixes sData. For C# I like to use a mixture of Hungarian notation for global variables and module level variables, camel casing for local variables, and Pascal casing for functions. For PHP I usually just use all lowercase, and use underscores for spaces. |
Ailure |
| ||
Hats Steam Board2 group Level: 121 Posts: 380/3965 EXP: 19783316 Next: 273380 Since: 02-19-07 From: Sweden, Skåne Last post: 3304 days Last view: 2055 days |
Xkeeper: True, but isn't it important to have a standards set when it's a group who codes?
They don't have to be strict, it can be rules such as "name variables and methods something sensible". You should just see some bad naming methods people use... ____________________ AIM: gamefreak1337, MSN: Emil_sim@spray.se, XMPP: ailure@xmpp.kafuka.org
|
Squash Monster |
| |||
Buster Beetle Level: 48 Posts: 42/469 EXP: 804620 Next: 18923 Since: 02-22-07 From: New York Last post: 5699 days Last view: 5699 days |
|
Ailure |
| ||
Hats Steam Board2 group Level: 121 Posts: 393/3965 EXP: 19783316 Next: 273380 Since: 02-19-07 From: Sweden, Skåne Last post: 3304 days Last view: 2055 days |
Hungarian notation seems to be even more unnecessary in languages like Java, especially when you use a small IDE and do proper encapsulation. ____________________ AIM: gamefreak1337, MSN: Emil_sim@spray.se, XMPP: ailure@xmpp.kafuka.org
|
Kernal |
| ||
Gone Level: 88 Posts: 483/1881 EXP: 6463564 Next: 187100 Since: 02-20-07 Last post: 6149 days Last view: 6140 days |
Did you know that Hungarian notation was put to the wrong use? It was originally used to differentiate variables that could be confused with each other in Word and Excel...something like wRow and wColumn for the cursor position within the window but cRow and cColumn for the cursor position within the cell. Then some other people at Microsoft saw it and decided to use similar prefixes to record the type of each variable instead of the function, which is where the notation went horribly wrong. Many common Windows functions are encoded with the wrong type because the variable type changed with the shift between 16-bit to 32-bit Windows but the names remained the same for compatibility.
Yay, my first edited post. |
Drag |
| ||
Spike Dragon Level: 57 Posts: 165/705 EXP: 1483288 Next: 2640 Since: 02-19-07 From: Last post: 3930 days Last view: 3930 days |
For forloops and other such things, I sometimes use x,y,z, but I also sometimes use i,j,k, etc.
My variable names are somewhat descriptive. My temporary variable names are usually temp, yay, whee, blah, etc... I sometimes add a p in front of variable names in function parameters if I have another global variable of the same name. This usually happens to me in java the most. Like: int size public void setSize(int pSize) { [tab] size = pSize; } ____________________ |
Main - Computing - Programming Poll #4: Variable Names | New thread | New reply |
© 2005-2023 Acmlm, blackhole89, Xkeeper et al. |
MySQL - queries: 87, rows: 115/116, time: 0.017 seconds. |