Against my better judgment I'll bite. I super dislike black's formatting, and I think it's really rare to actually see it in codebases. It wraps weirdly (sometimes not at all). I'd prefer to use yapf, but last I checked it still crashes on "f-strings". Here's a small example: basket.add({ apple.stem for satchel in satchels for apple in satchel }) Black formats this as: basket.add( { apple.stem for satchel in satchels…
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 mad…
Black – Uncompromising Python code formatter
131–140 of 251 posts
Re: Black – Uncompromising Python code formatter
#132Earlier quoted context omitted.
Are you sending unfortunate examples upstream? It's still beta, so it can be improved somewhat.
No, because I believe this is fundamentally unfixable. It's not a matter of changing this or that behavior, it's a matter of (apparent) formatting inconsistencies being important to convey intention and distinguish more important from less important bits. In the example I mentioned, I may sometimes choose to put a small dictionary initialization into a single line if it's just a detail, or may split it into multiple…
I you would be fine with 95% of what it does and just want it to ignore the 5% where you care the most, I think the tool could benefit you.
At least that’s how I feel about autoformatting in general.
Re: Black – Uncompromising Python code formatter
#133Against my better judgment I'll bite. I super dislike black's formatting, and I think it's really rare to actually see it in codebases. It wraps weirdly (sometimes not at all). I'd prefer to use yapf, but last I checked it still crashes on "f-strings". Here's a small example: basket.add({ apple.stem for satchel in satchels for apple in satchel }) Black formats this as: basket.add( { apple.stem for satchel in satchels…
Re: Black – Uncompromising Python code formatter
#134Re: Black – Uncompromising Python code formatter
#135Why on earth would it convert this: printable_chars = { 33, 34, 35 [...and another few hundred ] to printable_chars = { 33, 34, 35 [...and another few hundred lines ]
Re: Black – Uncompromising Python code formatter
#136This is a case where I'm completely decided. Everybody should use an autoformatter. The minimal benefit you get from custom formatting is completely outweighed by the uniformity, the consistency and readability of autoformatted code.
I think a nontrivial portion of Go’s success can be attributed to having a standard format and treating deviation as compiler errors. It is immensely valuable to be able to look at any Go code, whether in the toolchain, the standard library, or a random stackoverflow snippet, and not have to think about formatting at all.
you can't even comment out your code while debugging. annoying as hell.
Re: Black – Uncompromising Python code formatter
#137Earlier quoted context omitted.
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 mad…
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.
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..!)
Re: Black – Uncompromising Python code formatter
#138Earlier quoted context omitted.
I think that's why it self-describes as an opinionated formatter vs YAPF where one has very granular control. My understanding is that by using Black you're saying I choose to not express my opinions about formatting aesthetics and delegate that decision to Black instead.
I'm not a python person (for many years, at least) , but I'd choose black for a completely different reason. By using Black, I'm choosing standardization over my whims. Which, as a longtime Go dev and now Rust dev, I love formatters that are opinionated. I don't always love what Gofmt or Rustfmt do, but I definitely like consistency that the community has in code style. So I don't care what Black thinks - I care what…
I was initially grumpy about my org adopting black because I preferred single quotes, but the level of standardization is a huge win in my book. I never even think about my code style anymore, I just write it and then run black.
Re: Black – Uncompromising Python code formatter
#139Re: Black – Uncompromising Python code formatter
#140Why on earth would it convert this: printable_chars = { 33, 34, 35 [...and another few hundred ] to printable_chars = { 33, 34, 35 [...and another few hundred lines ]
Those look the same to me.