Re:Black – Uncompromising Python code formatter
by rav on Friday May 17, 2019 @12:34PM
(#19941165)
I completely agree that black does not format all examples in a nice manner, and your example is something I see pretty often. Whenever black adds too many indentation levels and line breaks in what should be a simple-enough statement, I simply refactor into multiple statements, e.g.
I concede that without black it wouldn't have made sense to make that refactoring, but since I really want to use an autoformatter, and black is the best autoformatter I have, I'd rather restructure my code slightly so that I can just use black 100% all the time.
[ Parent
| on HN ]
Re:Black – Uncompromising Python code formatter
by tedmiston on Friday May 17, 2019 @12:39PM
(#19941221)
It's an interesting meta thought that using the autoformatter changes the way you write your code. Not that that's implicitly a good or a bad thing, I just find it interesting.
Re:Black – Uncompromising Python code formatter
by acdha on Friday May 17, 2019 @08:29PM
(#19944823)
I think it’s under-appreciated when comparing tools like this. I’ve noticed that a bit since adopting Prettier and Black and one thing I’ve noticed during code review is that usually when I end up changing code structure to get better results from the tool, it’s a refactor that I probably would felt like I should have done but might have put off due to laziness even though it’s really not that much work.
I’m kind of thinking of it as something like baking some exercise into your day by putting a walk into your commute: the little nudge of not fighting the tool on something minor means you don’t skip little things, and over time that adds up more than it seems at first.
Every metatool you use does that - syntax highlighting, linters, formatters, ide’s, etc
You always end up adapting to the tool, while adapting the tool to you
Until you oneday reach a perfect harmony with your tool... until you introduce another one, and the equilibrium must once again be found.
Also of note, this is a general principle/behavior (eg you and your furniture..!)