Quote: Awful Identifier

Submitted by Jeremy
on February 27, 2008 - 8:29am

"`tmp' is an awful identifier, and renaming it to `temp' hardly improves it."

Meaning

Anonymous (not verified)
on
March 1, 2008 - 9:14am

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

Mr_Z
on
March 2, 2008 - 11:47am

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.

Anonymous (not verified)
on
March 4, 2008 - 7:48am

That's truly ugly. Congratulations! ;-)

Does it work?

..

handy (not verified)
on
March 25, 2008 - 8:41am

hehe I like it, looks just like my normal coding-style.. :( :D

Yes!

Mr_Z
on
March 4, 2008 - 8:47am

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

Lawrence D'Oliveiro (not verified)
on
February 29, 2008 - 5:32pm

At one time I tried to use plurals for type names, and singulars for variable and constant names, e.g.

type files = ... ;

var file : files;

Real programmers...

Anonymous (not verified)
on
February 27, 2008 - 11:42am

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

Anonymous (not verified)
on
February 28, 2008 - 4:58pm

french developers name their variables toto, tutu, titi, tata, tototo, tututu, tititi, etc. :)

Sad but true

renoXYZ (not verified)
on
February 29, 2008 - 12:59pm

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

Anonymous (not verified)
on
March 1, 2008 - 11:38am

"No, when looking at this, I didn't kill the developer..."

That was clearly a mistake ;)