Re:Plan 9 Coding Conventions for C
by mercurial on Wednesday May 22, 2013 @09:11AM
(#5750509)
This makes a good point for Python syntax, where you can't by construction end up in situations like that.
[ Parent
| on HN ]
Re:Plan 9 Coding Conventions for C
by jacobparker on Wednesday May 22, 2013 @09:19AM
(#5750565)
Note that any static analyzer that is worth something will warn about this in C/C++. For example, clang will warn with the option -Wdangling-else (implied by -Wall)
True, but the flip side is that in Python automatic indentation cannot possibly work.
Why not? vim indents one more when encountering a colon at the end of a line. It also de-indents when encountering a return or break statement. Of course in all other cases you have to de-indent manually, however, hitting backspace once is not more work than typing a closing curly brace.
What I mean is that you can't tell your editor to indent an arbitrary block of code.
Right, because a block of un-indented python is syntactically incorrect. It would be just like stripping all the brackets out of some C code and asking the editor to add brackets to the resulting mess properly.
Re:Plan 9 Coding Conventions for C
by papsosouid on Wednesday May 22, 2013 @10:56AM
(#5751287)
As maw points out, that is not a pure win, it is a tradeoff. And it is a tradeoff that I've found to be a really bad one. Being able to run indent over your code and have it automatically formatted is really helpful in large, long term projects where people come and go and weren't effectively forced into using one style.
You can do that with Python code, too.
Re:Plan 9 Coding Conventions for C
by papsosouid on Wednesday May 22, 2013 @03:04PM
(#5753037)
Sort of, but not quite. It is quite easy to get situations where code is wrong because of indentation mistakes, copy+paste, etc. All autopep can do is make your wrong code look consistent. Languages with some sort of block delimiter can't get wrong in this manner, so it is safe to munge together random sources with various indenting messes and then just run a tool over them.