4 ms·
This is great, except for the times that you take advantage of the fact that programming is essentially ascii art sometimes. I grant that these examples are ed
by taeric 14y ago
This is great, except for the times that you take advantage of the fact that programming is essentially ascii art sometimes. I grant that these examples are edge case in occurrence, but breaking the formatting really helps there.
And... I just can't bring myself to think that a rigid adherence to formatting will benefit any codebase as much as folks would like to think. As "edge case" as my reasons for wanting to break it, the straw men built up to show why it matters are even more ridiculous.
And this is completely ignoring that, once again, the largest collaboratively maintained source tree on the planet (that I am aware of) does not need this level of formatting adherence. Why do we think other projects do?
- to3m 14y agoI've not noticed any correlation either. If it's actually useful, which it may be, the degree of usefulness seems to be slight enough that it just gets lost in the noise. I guess people like this stuff because it's easy to check for, and easy to explain, and everybody's been annoyed by inconsistent code layout before, to one extent or another, so it can be an easy sell. It might also function as starter rules, getting a wayward team used to the simple idea of all working the same way, something that can be further extended in the future with more rigorous rule sets. It must be something like that, anyway, because I have to say that it doesn't seem to do anything for the actual quality of the code. I've torn my hair out in frustration over beautifully consistent code just as much as I have over the stuff that looks like a test case for a C parser - and it's precious little consolation if the stupid braces are in the same place on every line.
- df3n5 14y agoThis is true - there is a definite distinction that should be made between style and code quality. Good code could be ofuscated and it would still be good code. I don't think converting bad quality code to good quality code is something that can be automated. It should be something that is caught by code review and be flagged for discussion with the whole team if it is a general anti-pattern which is emerging in the codebase. When patterns / anti-patterns are observed, I think they should be called out and documented for future reference. This over time will lead to general coding guidelines, which are way more important than consistent syntax, as they should mitigate the hair pulling sessions you describe.
- unmole 14y agoThe largest collaboratively maintained source tree on the planet (that I am aware of) is the Linux Kernel. Just submit a 'badly' formatted piece of code to someone like Greg Kroah-Hartman and see what happens. Quoting a formal study[1]: "It is not merely a matter of aesthetics that programs should be written in a particular style. Rather there is a psychological basis for writing programs in a conventional manner: programmers have strong expectations that other programmers will follow these discourse rules. If the rules are violated, then the utility afforded by the expectations that programmers have built up over time is effectively nullified." [1] Soloway, Elliot, and Kate Ehrlich. 1984. “Empirical Studies of Programming Knowledge”, IEEE Transactions on Software Engineering SE-10, no. 5 (September): 595-609 [2] http://goo.gl/2bHwq http://goo.gl/2bHwq
- mpyne 14y agoThe kernel is actually not that large, all things considered (and why should it be, it's the freaking kernel). Although, it certainly seems the largest "professionally-engineered" source tree that I can think of. Greg's paper has a funny quote that's worth drilling out: "The original authors of UNIX placed their braces with the opening brace last on the line, and the closing brace first on the line, like: if (x is true) { we do y } Because of this, the kernel will be written in the same style." The reason is still arbitrary but I can certainly respect why that arbitrary decision is better than others.
- taeric 14y agoMy point was more that I would wager most "auto styler" tools will change code that is in the kernel. You are really just bringing up more of what I consider "straw men" in this argument. Terribly formatted code is of course terrible. Much of what folks argue about being "good code" is just nitpicky wastes of time. Take this snippet from the kernel: if (pages) { pages[i] = virt_to_page(start); if (pages[i]) page_cache_get(pages[i]); } if (vmas) vmas[i] = vma; This is just an arbitrary snippet, as I really have no familiarity with the code. But, alone in this snippet I already see at least two things that would make most format obsessed people go stupid. (Three in the actual code, but I don't know if the tabs will be visible to folks on this forum.) Edit: I forgot to add that I realize this segment actually conforms to the linux style guide. So... yeah, doesn't really say much other than to show that the kernel crew disagrees with most anyone you will ever hear online. It does not take too much effort to find snippets that actually do violate their own rules.