|
Re: How Important is Coding Style, and How Do You Enforce It?
|
Posted: Jan 31, 2007 6:26 PM
|
|
@James Watson
A few things spring to mind:
0. I agree with you that there is nothing greatly wrong with the text representation of Java, so why bother with a XML version. You could use a rigorously formatted, right down to the very last space, form of Java as the standard representation. The source code formatter I use Jalopy could probably do that.
1. The reason that I am using Jackpot is that it builds upon the Compiler API that is part of J6. The Compiler API exposes the AST that the compiler generates, but for read-only. The Jackpot API extends (literally extends the classes) in the Compiler API and adds write methods so that you can now read and write the compilers own AST. It will also then write this AST back to the source file, or you can continue with compilation, or do both. Jackpot is unfortunately Netbeans only, but the Compiler API is any Java 6 JDK.
2. The Compiler API isn't designed for a pretty printer and would not be capable of representing white space to the extent a pretty printer's AST can, but it seems to me to be ideal for decoupling the formatting from the syntax. For example for: an intelligent diff, a naming convention enforcer, etc.
3. If you had tools that where not sensitive to layout the coding conventions could be much more sensible; they would concentrate on stuff like public method names should begin with lower case, public classes upper case, public names should be Camel Case, if blocks should always have braces, etc. And not worry about stuff that is private or about if the braces are on the end of the line or not, etc.
4. The difficulty with converting to a canonical form isn't so much that it isn't possible. The Jackpot API could probably do it. But there are so many variations it is difficult to be sure that you have covered every possibility. In the case of my PEC project I also want to go back to the source form and ideally would like to go back to how the original programmer wrote the code. EG suppose that the original code used an import and the canonical form eliminated this by using a qualified name, then I modify the code, then I want to convert back to the original form so I want to add back in the import statements (this is tricky to get right).
5. Switching topics, I work on projects that different programmers have different styles. We do as someone else suggested in this forum which is use you own favourite style. If you are working on someone else's code reformat it as you like it and if necessary do a commit that is solely for the purpose of changing format. This seems to work fine. But it would be nice if the IDE automatically did this when committing.
|
|