|
| ▲ | zahlman 3 days ago | parent | next [-] |
| > just going through and moving shit around whenever you save a file. This only happens because the file doesn't already adhere to the rules it's implementing. These are normally highly configurable, and once your code complies to a standard, the tool prevents future code from pulling you away from that standard. > And sometimes, they actually insert bugs - string formatting errors are my favorite example. Do you have a concrete example? > Sometimes I'll get a pull request with like 2 lines of change and 120 lines of some reformating tool. Is your existing code formatting at least consistent? > You think I accept that? This is a social issue rather than a technical one. You can tell people in your development readme to use specific style rules, or even a project-wide precommit hook. If your own code is formatted with one of these tools, you can even (to my understanding) set up automated checks on GitHub's side. But of course you are free to reject any PR you want. |
| |
| ▲ | kristopolous 3 days ago | parent [-] | | I don't keep examples around to defend my stance on this, sorry. I left out my largest critique - spacing is semantic both for the compiler and the human. Often I police the whitespace very thoughtfully usually in code that also requires long comments for clarity. I care deeply about maintainability and legibility of code and try to consider future human readers everywhere. Then the formatter says "haha, fuck that!" That's my biggest personal gripe with it. It's consistency over clarity, conformity over craft. This all depends on what kind of code you're writing. Standard backend crud code in python with sqlalchemy? ok, pydantic with linters and formatters. But that should be written by llms these days anyways, if you're still doing it by hand you're doing it wrong. Honestly the jobs I sign up for demand a kind of care - mostly experimental and frontier work, so I am really frustrated when I'm prevented from exercising my professional judgement and doing what I think is best due to some bureaucratic red tape. I don't want the Wild West, I want disciplined senior engineers using professional consideration and judgement and not a bunch of onerous restricting tools assuming I don't know what I'm doing or why I'm doing it The language designers, compiler engineers, they are the actually competent people in the room and if they allowed for the flexibility I'll side with them over some hacked out set of rewriting regexs by some kid vibe coding on GitHub | | |
| ▲ | bogomog 3 days ago | parent [-] | | +1 to this. Why throw away an extra dimension of expression available by choices in formatting in the name of consistency? I find it helpful to use blank lines to separate code into "paragraphs". A complex conditional may be made more readable by extra space in some places an not others. A series of single line if statements might be clearer formatted lined up vertically, like a table. |
|
|
|
| ▲ | thfuran 4 days ago | parent | prev | next [-] |
| You have it entirely backwards. Enforcing a consistent format is useful precisely because it avoids pointless git noise from different people changing formatting differently as they go. |
|
| ▲ | rcxdude 4 days ago | parent | prev | next [-] |
| Running random formatters on random subsets of your code is not a good idea. If you want code in a repo to be formatted a certain way, you need to have one set of settings and enforce it, and yeah, reject anything that just has spurious formatting changes that someone else has run. |
|
| ▲ | mvieira38 3 days ago | parent | prev | next [-] |
| > This is most noticeable in open source contributions. Sometimes I'll get a pull request with like 2 lines of change and 120 lines of some reformating tool. This wouldn't happen nearly as much if you had a defined set of formatting rules plugged into CI instead of chaos |
| |
| ▲ | bluGill 3 days ago | parent [-] | | If the rule is not enforced in ci it isn't a rule. I've made that a mantra for a long time now and it helps. For a while I did verify formatting in ci but eventually we decided that formatiing wasn't as important as getting builds done fast. We still run other test and linters in ci and if they break fix the build but formatting isn't really that imbortant so we don't care. Yes our formatting is somewhat a mess but it isn't really that bad even after a decade of agreeing not to care. |
|
|
| ▲ | jchw 3 days ago | parent | prev | next [-] |
| Formatters breaking code is not something that happens in all language ecosystems; I think it's mostly a C++ and occasionally JS issue, but for gofmt and many other formatters just don't break code. It's also not really that common anyways. You can solve the Git noise issue by enforcing formatting in CI and keeping formatter configuration in repo. This is what most high quality open source projects will do. The purpose of this is not about "adhering to aesthetic ideologies", it's about not bothering people with the minutiae of yet another pointless set of formatting conventions. Most developers couldn't give a shit less where you think braces should go, or whether you like tabs or spaces, or whatever else, they care about more important things like data structures and writing more correct code. Having auto formatting enables them to effortlessly follow project norms without needing to, for every single repo they work in, carefully try to adhere to the documented formatting (which usually winds up being inconsistent eventually anyways, in projects without auto formatting, because humans are fallible.) The reason why people submit code with a huge formatting diff is usually because your project didn't ship a formatter manifest but their editor is configured to format on save. That's because probably most of the projects people work on now do actually use some form of automatic formatting, be it clang-format, gofmt, prettier, black, etc. so it winds up being necessary to special case your project to not try to run a formatter. It's still a beginner's mistake to actually commit and PR a huge reformatting, but it definitely happens by accident to even experienced devs when working on projects that have weird manual formatting. |
|
| ▲ | misiek08 4 days ago | parent | prev | next [-] |
| I’ve seen multiple repos with pre-hook and just CI running formatter on _modified_ code only. Those repos were the cleanest to date. |
|
| ▲ | kristopolous 3 days ago | parent | prev | next [-] |
| I'll sound off more on this. Formatters also value consistency over clarity. I break formatting all the time for the sake of clarity. Sometimes my comments are paragraphs long with citations and things are carefully broken down with interstitial comments and references and then the formatter fucks it all up and the linter says "wah this oblivious pedant rule isn't followed" The problem is it doesn't treat me like an adult And I'm not in this industry for dumb Nanny tools that scold me because they don't understand things |
|
| ▲ | galangalalgol 4 days ago | parent | prev | next [-] |
| Avoiding that situation is what I like about formatters. As long as the language has an obvious standard like rust or go. |
|
| ▲ | craftkiller 3 days ago | parent | prev | next [-] |
| > Sometimes I'll get a pull request with like 2 lines of change and 120 lines of some reformating tool. The reformatting tools should be CI-enforced so you'll only end up with sudden massive changes like this once when you start using auto-formatters. Regardless, tell your teammates to separate out formatting changes vs logic changes into separate commits (preferably separate PRs). Since they're auto-formatters it wouldn't even be any additional work, just: git fetch origin
git checkout origin/main
git checkout -b formatting
./run_the_autoformatter.bash
git commit -a -m "Ran the auto-formatter, which should have been enforced by the CI."
git push -u origin formatting
|
| |
|
| ▲ | WalterBright 3 days ago | parent | prev | next [-] |
| What I do is make two separate PRs - one for the coding change, the other for reformatting only. |
|
| ▲ | johnnypangs 3 days ago | parent | prev | next [-] |
| I’ve used this before, it helps when you format the entire repo and remove the one commit from the history https://docs.github.com/en/repositories/working-with-files/u... |
|
| ▲ | triknomeister 3 days ago | parent | prev [-] |
| formatting on git diffs is a concept which should be embraced. |
| |