5 ms·
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 inde
by rav 7y ago
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.
stems = {
apple.stem for satchel in satchels for apple in satchel
}
basket.add(stems)
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.
- tedmiston 7y agoIt'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.
- setr 7y agoEvery 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..!)
- acdha 7y agoI 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.
- ali_m 7y agoI actually much prefer Black's version in this case. I find nested comprehensions quite a lot easier to read if they are broken onto multiple lines.
- deleted 7y ago[deleted]
- jordic 7y agoI'm doing the same :/