Hacker News new | past | comments | ask | show | jobs | submit login

Take, for example, the declaration parsing example and honestly tell me that this isn't crappy code by any modern standard:

    enum { NAME, PARENS, BRACKETS };
    void dcl(void);
    void dirdcl(void);
    int gettoken(void);
    int tokentype;
    char token[MAXTOKEN];
    char name[MAXTOKEN];
    char datatype[MAXTOKEN]; /* data type = char, int, etc. */
    char out[1000];

    main()  /* convert declaration to words */
    {
        while (gettoken() != EOF) {   /* 1st token on line */
            strcpy(datatype, token);  /* is the datatype */
            out[0] = '\0';
            dcl();       /* parse rest of line */
            if (tokentype != '\n')
                printf("syntax error\n");
            printf("%s: %s %s\n", name, out, datatype);
        }
        return 0; 
    }



Pg 124 from 2nd edition where this code is pulled (emphasis mine):

"[T]he programs are intended to be illustrative, not bullet-proof, there are significant restrictions on dcl."

In context this code illustrates the points they're trying to convey about complicated declarations quite well and is a precursor to understanding typedef later in the book.

Also, you left the nice inline comments off the variable declaration block.


I would like to see where typedef could have been used?


"Modern standard" or not, I find this piece of code highly readable, and, in general, very good for what it does, at the level (of simplicity, perhaps even "primitivism") at which it was intended to do that.


This piece of code is crap - it's not functional, keeps implicit state.


Not all quality code is functional.


Could someone point out the craps in the code ? I only noticed excess use of global variables , and out array(can't figure out why it was index only at zero)




Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact

Search: