|
From: Nicholas N. <n.n...@gm...> - 2023-04-26 10:32:26
|
On Sun, 23 Apr 2023 at 03:44, Mark Wielaard <ma...@kl...> wrote: > > But why do you want to reformat all the existing code? > Isn't it enough if people have easy tools to format new hunks? > > I am happy if we encourage people to use code formatters for > new/changed code. But forcing a reformat of the whole project on > people seems like a bad idea. > > I think Paul's recent accident with clang-format shows why it is not a > good idea to try to reformat any existing code. It just introduces > huge arbitrary changes. > They are not arbitrary changes, they are improvements. Auto-formatting the whole codebase has some major advantages. - Simplicity. "Format all C code with clang-format" is simpler than "Format new C code with clang-format, but leave old C code alone." And partial application can lead to weird results when you make a change that results in a tight interleaving of changed and unchanged lines. - Consistency. Instead of a mishmash of styles, everything is consistent. `foo ( bar )` vs `foo(bar)` is one prime example of an existing inconsistency, with both versions appearing all over the place. It makes me grumpy. - Readability. A lot of the current style choices are just bad. Some of the worst problems can't be fixed in a piecemeal fashion, e.g. three space indents are weird and terrible. There are some implicit principles that inform my opinions here. - The latest revision of the code is the most important revision. This means it's worth making changes to improve things. - Developer experience is important. Code should be enjoyable to work on. There are many aspects to this, and code formatting is one of them. "It's always been like this" is a weak justification for many things. As I understand it, there are two main objections to mass-reformatting. - It breaks `git blame`. But as we've seen, this is entirely fixable. - "If it ain't broken, don't fix it." But I argue that it the current inconsistent formatting is a form of brokenness. Of course some care is required to fix it, e.g. the particular style should be chosen with care, and diffs should be reviewed by humans and not just blindly accepted. But there are high-quality, widely-used tools that make it straightforward. We should use them. Nick |