In general I try to name my variables such that they represent what they contain.
However, in small functions I generally use one-letter variables, such as `i' for index, `c' for character, `n' for count, `s' for string, and `p' for pointer, and so on.
I give variables defined at file scope more meaningful names (such as `foo_list'), since they're visible to the entire translation unit.
Yes it does, despite the one apparent "bug," where I used '=' instead of '==' in an if statement. (I never noticed the typo until a couple years after I wrote it.) If you follow the logic, though, the '==' would have always been true anyway.
Meaning
In general I try to name my variables such that they represent what they contain.
However, in small functions I generally use one-letter variables, such as `i' for index, `c' for character, `n' for count, `s' for string, and `p' for pointer, and so on.
I give variables defined at file scope more meaningful names (such as `foo_list'), since they're visible to the entire translation unit.
Same here
So do I, although I like to hold up the following function as my personal "worst," taking this perhaps much too far:
static char *dl1="[<{('\"",*dl2="]>})'\"",*dl3="<("; void strip_addr(char *s, char *strip) /* grabs just user@host */ { char *s1=s,*s2,*s3,*s4; char buf[3072]; int i; s4=buf; while (1) { s3=s4; while (*s1) { if (strchr(dl3,*s1)) break; *s4++=*s1++; } if (!*s1) break; if (*s1=='(') { while (*s1 && *s1++!=')'); } else if (*s1='<') { s1++; s4=s3; while (*s1 && *s1!='>') *s4++=*s1++; if (!*s1) { *s4=0; break; } *s1++; *s4++=*s1++; } } *s4=0; s1=strip; s2=buf; i=0; while (*s2 && *s2!=' ') { *s1++=*s2++; i++; } if (i<5) strcpy(s1,"@msg.domainname.com"); else *s1=0; }That was written over a decade ago. My coding style has improved since then. ;-)
--
Program Intellivision and play Space Patrol!
Wow.
That's truly ugly. Congratulations! ;-)
Does it work?
..
hehe I like it, looks just like my normal coding-style.. :( :D
Yes!
Yes it does, despite the one apparent "bug," where I used '=' instead of '==' in an if statement. (I never noticed the typo until a couple years after I wrote it.) If you follow the logic, though, the '==' would have always been true anyway.
--
Program Intellivision and play Space Patrol!
Naming conventions
At one time I tried to use plurals for type names, and singulars for variable and constant names, e.g.
Real programmers...
Real programmers name their variables foo, bar, baz, qux, quux, plugh, xyzzy, and thud. Their meaning is pretty obvious to me ;-p
french developers name their
french developers name their variables toto, tutu, titi, tata, tototo, tututu, tititi, etc. :)
Sad but true
While French, I remember a prototype in C in which variables were named i1, i2, ii, j, ij, etc..
In two files with several thousand of lines eacn, and 'useless' array between variables due to buffer overflow..
No, when looking at this, I didn't kill the developer, but let's say that was close!
"No, when looking at this, I
"No, when looking at this, I didn't kill the developer..."
That was clearly a mistake ;)