--John McCarthy, http://www.infoq.com/interviews/Steele-Interviews-John-McCar...
Of course, trivial things like braces on the same or next line or whitespace around operators are solvable that way, but in general, as long as source code is text (and it will remain that way for quite some time). What perpetuates this state is obviously that we have lots of tools that deal with text and very few that deal with more specialised content. In general I find this sad, though, as text is often neither easiest to work with nor most expressive, despite of what diehard Unix users say.
What would be really lovely in my eyes woul be a source control tool that actually understood its content and could say "order of parameters of that function was changed" or "method added", etc. It's sometimes astonishing how the pursuit of optimal diffs masks the intent of a change where an added method diff starts with the closing brace of the previous method, for example.
[1]: http://welbog.homeip.net/glue/71/Whitespace_is_not_a_problem
In Python you can get the whole return statement. Especially when adding a similar type of method, e.g.: Django view functions. Makes
git add -p
more fun. * you can elect to turn off formatting for sections of your code
* you can save/export your formatting convention in an XML file that looks like this: http://pastebin.com/fKjKRuZg
* you can import that code convention into new/other projects
* you can select any number of files or projects and choose to apply the formatting to the Java source
* the result is very readable
This might not tie in directly to your source control tool as is but would make taming and standardizing source from multiple developers a bit easier. As long as every contributor's code eventually is coerced into this form your own/central copy can easily be diff'ed across versions. Also, you could apply other conventions with other formatters for clients that see things differently.Automatic reformatting is evil - sometimes codes is more readable if formatted in a particular way. Readability and maintainability always trumps adhering to rules.
But what I'm saying is that the formatting of a file may contain contextual clues that will help someone reading the code to understand what it does. Formatting isn't just chrome around the code.
Example: In Java, when writing a custom predicate to filter by foos that are bars, I prefer
filter(myList, new Predicate<Foo>() {
@Override public boolean apply(Foo foo) { return foo.isBar(); } });
to filter(myList, new Predicate<Foo>() {
@Override
public boolean apply(Foo foo) {
return foo.isBar();
}
});
(filter is statically imported from Collections2 in Guava)especially when there are multiple of them and they line up neatly underneath each other.
Any meaningful autoformatter would change the latter to the former, and in the process loose readability.
EDIT: Another example would be when using the builder pattern - getting those methods to line up to be neatly readable often takes some none-standard indentation.
1. There is an agreed autoformatting template, checked into version control.
2. It is always ok to format the lines you are working on however you like, with the understanding that other people may run the autoformatter on the file.
3. It is always ok to run the autoformatter on a file you are working on (autoformatters only really work at file granularity).
4. It is not ok to format code you are not working on.
Changing the name of a constant on line three doesn't give you license to autoformat the rest of the file.
http://www.html5rocks.com/en/tutorials/developertools/source...