Original Post
I don't know why but alot of the stuff in the K&R coding standards seem wierd to be and wanted to get your guys opinions. I will just go through each section that i disagree which. Naming: K&R : "A variable or function name should be sufficient to understand the meaning, while remaining concise. The shorter the lifespan or scope of a variable, the shorter its name should be; conversely, the more important a variable, and the more places it is used, the more descriptive that name should be." I really don't think naming a variables shorter if it is not used as much is really a good idea. I mean K&R sytle would have a variables named nelems which if i where jsut to look at that, I would be a little confused and would not know what it mean right away but I would name the name variable number_of_elements and to me that is much more clear becuase i knwo right away that it is the number of elements(i may not know what elements it is referring to but I would just need to look at the code around quickly, alot wuicker then i would if i needed to figure out what nelems means). Indentation and Spacing: This is the example on how to do it K&R style: And this is how I would do it: For me, my way just seems alot clearer and cleaner. The major issue with K&R way is when I see major nested if statements. I have see some if statements that written in the K&R style, I just don't know where any if statement ends just by looking at the code but my way I can clearly see it. Another thing is the space between the statement and the parameters like if () seem like a waste of a space to me, it do not do anything good for the reading of the code. Comments: I for the most part agree with K&R. Other Things I See That I Am Not Sure If It Part Of K&R: One common thing i see is when declaring variables/function/classes they are declared like firstFunction, secondFucntion, firstVariable, secondVariable. For me the way I declare variables/function/classes are all different so i know which is which just by looking at the name. I declare variable in all lowercase and underspace for spaces, I declare function which all words first letter capped, and i delcare classes like function just with a 'C' in front of it. also when i declare a class variable i like to add "_object" to the end of it becuase that way i know it is a object just by looking at it. Also with any members(class variables), i use a underscore infront of it that way i know when i am dealing with member inside fo a class function if i happen to have a parameter that is the same name(usually with Set functions). Here is an example of all that. You guys disagree with me on any of these points, just like to know what you guys code standards are.
for (i=0; str != '\0'; i++) {
if (str == ' ') {
if (strcmp(&str[i+1], "static") == 0) {
...
}
else {
if (strcmp(&str[i+1], "final") == 0) {
...
}
}
}
}
for(i=0; str != '\0'; i++)
{
if(str == ' ')
{
if(strcmp(&str[i+1], "static") == 0)
{
...
}
else
{
if(strcmp(&str[i+1], "final") == 0)
{
...
}
}
}
}
//variable
int test_variable;
//function
void function DoSomethingFun()
{
}
//class
class CFile
{
public:
void SetTest(int test)
{
_test = test;
}
private:
int _test;
};
//sorry my c/cplusplus is a bit rusty becuase i have been doing php for the pass 1-2 years
CFile file_object = new CFile;