← Back to context

Comment by rbanffy

6 years ago

> Surely the indentation itself is a huge visual clue

Apple had a security bug that stemmed from indented C code that was indented but not within brackets. The second line of an if was not under the condition, but was indented the same as the first line.

I myself prefer to use type to convey structure and color to convey semantics. Having keywords boldfaced helps structure to stand out while coloring parameters, locals and globals differently would help meaning to surface more evidently.

For what it’s worth, it was introduced as a failure of an automated merge process and not direct programmer entry. Had braces been used the error would likely not have been caused (or would have compilation errors) but the fact that it appeared indented you the same level is not because a programmer made a mistake.

It is perhaps more telling that the code was compiled without an error indicating dead code which was the net effect of this merge, but sadly warning free code isn’t a goal.

  • True, but just by looking at the code it looked right. An autoformat tool would have made the mistake more visible. I wonder if popular linters would pick it up (not only the lack of braces as a rule, but the misleading indentation)

    • GCC version 6 and later actually warn about misleading indentation if you use -Wall (which you should), and you can turn on -Werror to ensure you don't forget to fix the mistakes.

      1 reply →

> Apple had a security bug that stemmed from indented C code that was indented but not within brackets.

Sure, but if your editor can correctly color based on nesting it could very well fix the indentation to be correct as well.

> I myself prefer to use type to convey structure and color to convey semantics. Having keywords boldfaced helps structure to stand out while coloring parameters, locals and globals differently would help meaning to surface more evidently.

That makes sense.

  • > if your editor can correctly color based on nesting it could very well fix the indentation to be correct as well.

    One more reason to run an autoformat tool on commit. ;-)