What's in a Coding Style?

Uncategorized Add comments

I commented before about the religious holy-war of coding styles:

K&R
int main (int argc, char *argv[])
{
    if (0 == argc) {
        do_something();
    }
    return 0;
}
Consistent K&R
int main (int argc, char *argv[]) {
    if (0 == argc) {
        do_something();
    }
    return 0;
}

To revisit, when it comes down to it, K&R format is indeed inconsistent, and is a source of error for new and experienced engineer alike, but arguing about it consumes more time.

There’s a similar amount of time wasted in re-formatting back to a format if you happen to like the other format compared to the project lead, so for your coding changes you have to reformat back and forth.

Reviewing merges and having to skip over whitespace changes are simply a waste — the computer should know better. Sometimes, I miss how BASIC interpreted every line as typed, and stored it as tokens, producing canonical consistent code from those tokens when listed. It’s hard to make a whitespace error or cause hundreds of LOC of change from an indent when the code is stored tokenized.

To get around this time-sink, when I was the designer/lead-engineer for Smallfoot, I caused checkins to be formatted (using indent and bcpp. This was done in a .wrapper script, so it was automatic.

The other automation was the countdown timer: after 10 minutes of idle time (ie commits have finished), the sourcecode server would checkout code, do a build, re-generate the in-code API documentation, and run all the self-tests. All of our example configs were used as self-tests, ensuring that any example we had was tested. The key of this boasting (I’m proud of what we did) is to show that automation makes life easier — including nit-picking over coding style — so that engineers can code, code, code, and get updates on things that the Machine found that he/she might have missed.

I’m all for hardware doing the machine-work, and meatware doing the people work. Including the coding-style normalization.

One Response to “What's in a Coding Style?”

  1. XHTML 2/HTML 5 Comic Strip Says:

    […] What’s in a Coding Style? Jul […]

Leave a Reply

WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS Log in