3 ms·
Immediately this sounds wrong to me, because even talking of "re-arranging my code" is something that should be avoided. Let auto-formatters format. This is es
by eterm 3y ago
Immediately this sounds wrong to me, because even talking of "re-arranging my code" is something that should be avoided.
Let auto-formatters format. This is especially important in team situations where formatting enforced via editorconfig will keep merge conflicts to a minimum. Even working solo having a forced style will keep code consistent and remove distracting unimportant changes from refactors.
Define a style, have tooling enforce it.
- delichon 3y ago> ...even talking of "re-arranging my code" is something that should be avoided. Why? I find a well organized code file to be easier to read, e.g. grouped together constants, related declarations, class methods, instance methods etc. And to display those groups in some common order so it's easy to find them. An auto-formatter would have to have deep knowledge of intents to do that automatically.
- leduyquang753 3y agoSometimes there are situational choices that autoformatters cannot comprehend. I also failed to make formatters follow the style choices I use, they were just not configurable enough.
- kstrauser 3y ago> Sometimes there are situational choices that autoformatters cannot comprehend. I haven't stumbled across that. Could you give an example? > I also failed to make formatters follow the style choices I use, they were just not configurable enough. That's kind of the whole point. I love, love, love Python's Black formatter. In my opinion, it chose the wrong default for quoting strings (i.e. it re-writes single quotes as double quotes), which irked me until I gave up and accepted it. In return, I no longer have to put up with my coworkers' insane style choices, just as they no longer have to tolerate mine. With a single addition to our CI pipeline, the days of dumb arguments about the "right" way to format our code came to an end.
- codetrotter 3y agoLikewise with rustfmt I apply zero customization to it. If rustfmt thinks the code should be formatted some way, so be it. I have other things to spend my energy on, unrelated to any particular formatting choices.
- kstrauser 3y agoSame here. "OK, this is what Rust is supposed to look like? Fine." And now I never have to think about it again.
- secondcoming 3y ago> Could you give an example? One thing clang-format ruined for me is when I laid code out in the same indentation as the JSON it was generating. E.g. json .startObject("root") .startArray("data") .insert(1) .endArray() .endObject(); became json .startObject("root") .startArray("data") .insert(1) .endArray() .endObject();
- leduyquang753 3y ago> I gave up and accepted it. Some people also said "just accept it" and that's part of why I ditched it. If it can be helped I do not accept it. This is not limited to code formatters, I want to have control over the things I personally use. I want to be comfortable doing my stuff.
- kstrauser 3y agoYou've gotta choose your battles. In all the ways I might want to express myself with a computer, the exact formatting of my code is almost never one of them.
- refactor_master 3y agoIn our code base every “fmt: off” is compensating for a lack of scopes, smaller functions, variables, etc. Instead of cutting down on repetition we have dozens of consecutive lines of repetition. But nicely formatted repetition. Until that inevitable day where you have to change something, and everything breaks because you’re only supposed to change 90 of the 100 almost identical lines.
- nicole_express 3y agoIn 99% of settings I am a big fan of auto-formatting as well, though there are definitely cases where I feel you're better off on your own-- the big example that comes to mind is assembly coding, I think the standard formatting there is very restrictive (since it dates back to the early days of more limited editors) and customized formatting can aid understanding significantly.
- bee_rider 3y agoAn auto-formatter that is designed to work for someone who doesn’t have syntax on seems like it should work for everybody else, too, though, right? The :syntax off coder becomes the canary.
- nemetroid 3y agoFormatting is only a (small) part of coding style. Out of the given examples, only the first one is something an auto-formatter would solve, and even then only in a limited sense: * applying recurring visual patterns * writing less convoluted statements * keeping my files short and concise
- JohnFen 3y ago> Define a style, have tooling enforce it. I agree, but I can't stand it when the formatting is applied while I'm typing. I prefer to run it through a prettifier afterwards as a separate step.