3 ms·
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 inconsistenci
by CrLf 7y ago
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 lines if it's important enough for someone reading the code to pay attention to it before going further.
This simply cannot be decided by an automatic formatter without it knowing the code's purpose which, for now, requires a human brain.
Someone mentioned elsewhere that automatic formatters remove the cognitive load of formatting code, but I argue that load is an intrinsic part of programming, because it is (for the most part) the effort of communicating to the next person that comes along.
- zild3d 7y agowhy not use their ```# fmt: off``` ? I have not used Black, but considering it so I am curious about these occasional situations where you want to override auto-formatting
- arnioxux 7y agoI write a lot of scientific code with python and in those cases you really want your equations and matrix columns aligned for readability. These matrices appear so often adding fmt:off destroys the readability/elegance gain from the clever formatting. Here's an example snippet by Peter Norvig that is beautifully formatted: def neighbors4(point): "The four neighboring squares." x, y = point return ( (x, y-1), (x-1, y), (x+1, y), (x, y+1)) def neighbors8(point): "The eight neighboring squares." x, y = point return ((x-1, y-1), (x, y-1), (x+1, y-1), (x-1, y), (x+1, y), (x-1, y+1), (x, y+1), (x+1, y+1))
- skybrian 7y agoWell sure, but an automatic formatter can still be better or worse. Maybe it won't be as good as hand-crafted formatting, but more bad examples can be avoided.
- lysium 7y agoThere is #format off for these few cases.
- hrktb 7y agoI don’t code in python so have no opinion on Black, but most code formatter can be adjusted to exclude some cases of formatting. 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.
- akvadrako 7y agoBlack is specifically designed to avoid being customizable, so you can't just exclude some cases.