News for hackers. Stuff that matters.
Re:Plan 9 Coding Conventions for C by mercurial on Wednesday May 22, 2013 @09:14AM (#5750531)
Sure, but how often does this happen in practice? I have worked with 'no convention'/'multiple conventions'/'mostly no braces for single statements' and have never seen this particular mistake. I can see how it would be difficult to track down, on the other hand, braces for single comments add to line noise.
Re:Plan 9 Coding Conventions for C by k3n on Wednesday May 22, 2013 @10:58AM (#5751300)
I've encountered it just enough times to avoid it 100%. I think in my scenario, the problems have been compounded by an overall lax (lazy) coding style on the part of my predecessors, in that many of them were junior devs who virtually made-up their own coding styles. These devs treated whitespace like it cost money, and avoided any unrequired use of spaces, tabs, and newlines.

These types of conventions -- no curlies around simple blocks -- aren't too bad if a) your devs are adequately seasoned, and b) your devs believe in whitespace.

For instance, this isn't really so bad:

    if (foo)
      foo();
    else
      bar();
Hell, that's clean!

But it's stuff like this that causes issues:

    if(foo)foo();
    else bar();
Sometimes I'm lucky and find this:

    if (foo)
      foo();
    else {
      bar();
      baz();
    }
The best is abominations like this though; first, the sane formatting:

    if (foo)
      while (i++ < x)
        foo(i);
    else
      bar();
Or, as I have found it:

    if(foo)while(i++<x)foo(i);
    else bar();
Seriously, that's enough for me to revoke commit privs.
Re:Plan 9 Coding Conventions for C by to3m on Wednesday May 22, 2013 @11:56AM (#5751693)
I've seen it once, in 13 years of working professionally in C. I think two people changed the same one-line if statement, but for two different reasons (probably adding two different new features to the same bit of code). And after an automatic merge it became something like this:

    if(flag)
        set_other_flag=1;
        call_function();
(both lines necessary)

Anyway, it didn't take long to narrow it down to that bit of code but it took a few more minutes to figure out why the function was always getting called. I couldn't work out what was going on until I looked at the disassembly and was forced to reassess my opinion of what code was actually being compiled. Too much python in my diet, perhaps.

I remember being surprised at the time that it had taken so long for this to happen, and I made a mental note to keep an eye out for more occurrences. That was summer 2006, and I haven't seen it happen since.

Re:Plan 9 Coding Conventions for C by barrkel on Wednesday May 22, 2013 @09:48AM (#5750763)
I've worked on multi-million line projects and have also never seen this mistake made. So in my experience, it is so vanishingly rare that the costs in visual gunk and decreased code density are not worth it.

A lint tool checking for suspicious indentation would be a better use of labour.