|
|
View Full Version : Naming conventions
Blindman 03-19-03, 02:48 AM Dang naming conventions…
This is the third Job in the last several months that the stupid naming convention of appending the type of a variable to the beginning of its name has been required.. 3 god dang letters this time.
E.g.
Float fltMonkeyNutSize = 0.2f;
Int intMonkeyNutCount = 2;
Monkey *mkyMonkey = new Monkey();
In the age of auto complete it is a nightmare. I will never adopt this stupid system in any of my own projects no matter how many people are involved.
How hard is it to find the type of a variable when taking over some code.. I spend more time stepping through the Auto complete list then I would just scrolling up and seeing its type where it is declared..
Please all those that agree please help me stamp out this absurd convention. If we feel it is needed, please move it to the end of the name, its so much easier..
Blindman 03-23-03, 05:43 AM Just to move this message up the list a bit..
I would appreciate a vote on this.. and thanks to those that voted...
Well, actually, i kind of like them. Especially for certain scripting languages, where variant typing is used and no datatype is given with declaration.
Secondly, it makes code more readable, without having to guess what datatype it is. Every now and then i find myself with a shabby old laptop which can perfectly handle TextPad but not a full blown ide. In those times of lacking an auto compl. it really does make life a bit easier...
I could very well live with the compromise of putting it to the end of the name, though.
Probably just because im still rather amateur, but I enjoy it when i have a naming convention (no matter how stupid it is) placed upon me since I always have trouble sticking to one of my own. I really just need to find a good one and decide on it. Any one with good advice?
-AntonK
river-wind 03-26-03, 09:00 AM I usually go with the following:
"type id"Varname_description if needed
example:
fMoneyTaken_march
cAttyLastName
cAttyMainOffce_2003
with any secondary words capitalised for readability (I think it's called Camel Casing)
counters are single letters, or single letter w/ an identifier:
x,y,z,q,f1,f2,f3,f4,f5,f6,f10,x10, etc
Arrays have "array" or "a" appended to the end, depending on the language:
cAttyNames_a
These days, especially in quick development environments, RAM and hard drive space are not the limiting factors, the programmers are. Having easy to understand variable names costs in memory space used, but allows for a programmer to understand the goal of the code easier, and therefor fix any bugs in it faster. This applies to programmers new to a project, or to you remembering what you did two years ago. I'm sure we all heard the stories during Y2K fixes where programmers has set the date variable to the name of a pet, and no one could easily figure out which variable held the two digit date in order to fix the code. :(
Having the type and description availasble in the var name also helps when working on huge functions- a case where the var declaration may not be easy to find, or even in a different file! Talk about hard to find!
just my method. any one do things differently? why? any methods better, and hold all(or more) information in a tighter space?
Blindman 03-27-03, 02:44 AM I agree with river-wind..
For my own project I imbed a description of the type in the name.
For example
int monkeyCount = 1;
float monkeySize = 1.2f;
string monkeyName = new string("Einstein");
The types to me are obvious.. Counts are integers..
Size cant be an integer and must be a float.
A name must be a string..
I know that there are many types of integers, floats, strings...(Byte,Char,Int,Word,Dword,unsigned, etc...)
But most of the time it does not matter..
int monkeyCount;
word monkeyCount;
valid for monkeyCount in both declarations.
monkeyCount += 1;
In projects where there must be a clear difference in types. e.g. 3D programming where the hardware can only except 32bit floats and your world is defined in 64bit floats, you must know. But put it at the end.
I am egger to change the convention because of the hassle with code complete.. Soon editors will also supply the var type.
Im in it for increased programming speed.
CompiledMonkey 03-27-03, 02:04 PM I think it depends. I don't see why having the variable data type included is such a great idea unless you have a large amount of developers working on the project. Also, if you are using a modern IDE (JBuilder/VS.NET), you have a window showing you methods and variables within the class you have open.
AgamemnoN 03-27-03, 07:48 PM I learned to use naming conventions in the college with my "home works", and when you start using it, you will never leave it ;)
In the company i work for, we have a strong name convention that any of the developers are capable of identifying the type, the size, the name and the scope of a variable/class/function just by it's name, it's definetly an awesome aproach to group programming...
I Think that every programmer will start using it someday, in the beginning everybody complains about naming rules, but once you start using, the benefits are so explicit that you can't find arguments to complain ;)
Would you please be able to direct me to some documentation about your naming scheme. Something formal, with rules and such.. I like the sound of it, and would like to start using it if i had the formal rules.
-AntonK
AgamemnoN 03-29-03, 02:21 PM Anton, I don't think the naming convention we use at Voxel is something formal, it was probably some study made by my employers and used inside the company...
I Know that for comments we use the JavaDoc standart but the organization of the names it's not universal standart...
Originally posted by AntonK
Would you please be able to direct me to some documentation about your naming scheme. Something formal, with rules and such.. I like the sound of it, and would like to start using it if i had the formal rules.
-AntonK
I go with Anton..
can u jus' pass on a document or kind of abstract on Naming convention??
In my company, we are into the implementation phase in the product i'm in.. may it would be of muct use to me...
rajesh
Blindman 04-17-03, 12:10 PM that any of the developers are capable of identifying the type, the size, the name and the scope of a variable/class/function just by it's name
That sound great AgamemnoN. But to do this use must abbreviate all the different types that are part of the project. Every time a new type is introduce a new abbreviation of the type must be created.
Do you have a list of all the types used and the abbreviations, usually updated weekly or on request, so that you can lookup the abbreviation of a type?
Code complete is making the need for this obsolete. Type abbreviation hampers the use of code complete.
When C stepped to C++ it was optimized for coding speed.
No longer
Counter = Counter + 1;
Now
Counter += 1;
Or
Counter++;
That why It was called C++.
Anyone who moves from C++ to Pascal or older versions of VB will know the pain.
I'm almost sure you've always been able to do those things in C. I'm pretty sure the original C ISO standard allowed that.
-AntonK
Originally posted by Blindman
Please all those that agree please help me stamp out this absurd convention. If we feel it is needed, please move it to the end of the name, its so much easier..
naming conventions are essential to good, reliable, maintanable code. if you dont like it, learn to type faster and dont use autocomplete - like you say, you spend more time stepping throught he list
or, you can write an extension to your IDE that ignores the first 3 letters of variable names when autocompleting. or, you can write an extension that hides the type for certain vriables.. silently adding it in when compiling
end of the day though. ,.we arent talking about throwing up code at a rate of 5000 lines a day.. we are talking about throwing it up at 1000 lines a day and generating something that is actually readable by the person that takes over your job when youre done./. dont be so darn selfish.. youre still getting paid the same :)
Originally posted by river-wind
Having easy to understand variable names costs in memory space used,
i'd like to know how you arrive at this conclusion, given that compilers turn all human-typed variable names into some machine representation..
i dont blieve that a program written with single letter variable names will occupy any less memory on disk, or when rnning,. than the same program having 30+ character var names..
Originally posted by Blindman
I agree with river-wind..
Size cant be an integer
A name must be a string..
Im in it for increased programming speed.
Solid statements there.. youre saying that you cant think of any instance where something will have an integer size or a numerical name? i dont think your convention is sufficient to cover enough possibilities, and your source would still require some reading to understand basic types..
"more haste, less speed" :)
Blindman 04-21-03, 09:08 AM I have created and produced about 20 software solutions for projects as diverse as arcade computer games to video store maintenance systems. Plus many more home projects in games and visualization. I have never enforced any naming conventions on my programmers apart from don’t use the underscore to delimit var names.
I have never been asked to modify code, past the completion date. Because my code does what it was sold to do.
Naming conventions say that code is almost perfect, but we have set up systems that will help us when it does not stand up.. Why should the contractors pay for probable software errors.
more haste, less speed" No haste just speed.. More projects. More money.. Better software.
If a programmer cant work out what type of a var loopCount is then go find work else where.
but thats just it! its not necessary that you use an int for a loopCount.. you might be dealing with floats
i doo see what youre saying, because i oinly really use a naming convention as mentioned here in my own projects when im writing a GUI.. many components will have similar real names, like a label and a text field that are related to each other.. ti distinct them with jlab_ and jtxf_
i would say tho, that for large projects, there the entire scope of a variable cannot be seen on one screenful of text, that a vartype indicator be used.. loops generally are small, so its okay to use "i" for example, as you can see the whole loop in your text editor
i was caught out by this last night.. i had called an InputStream "i" in a superclass, in the subclass i was making references to "i" and the only "i" i could see wasnt even in scope, but part of the for loop immediately above the mystery "i".. if i had better named the variable it would have saved me 10 mins (and i know this aint so much a prefix as a retarded naming issue)
apollo2011 05-07-03, 06:03 PM Ivoted for only in large projects however I do believe this is an advange for you as the programmer. If you aren't good at keeping track of the variables from day to day then I suggest that you use them.
|