4 ms·
Because it’s optimised for producing the smallest diff once it’s already been formatted and a change is made. If you add a single item to your preferred style,
by jsmeaton 7y ago
Because it’s optimised for producing the smallest diff once it’s already been formatted and a change is made.
If you add a single item to your preferred style, the entire thing has to be reflowed.
- georgyo 7y agoThe line length thing is what I hate the most about black. It's way too religious. For strings, it will format it like he formatted the array, and adding a word will reflow the entire block of text.
- anoncake 7y agoSometimes, optimizing for the smallest diff is clearly not worth it. For example: months = ["January", "February", "March", ...] A human can make a smart decision, an autoformatter can't.
- davidjhall 7y agoPlus, finding the change isn't that hard, compared to munging your 1 or 2 line assignment into 30. A good diff will tell you: foo = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30 ] vs. >> foo = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30 ] Better ones will underline the offending characters.
- yellowapple 7y agoOnly if I add an item in the middle. If I'm always appending, then only the last line will show a diff, and said diff will be for the added entry. Even in a case where I need to add an item in the middle, the diff will - again - only start where I actually added an item, and any human can readily see that the rest of the downstream diffs were from the reflow. Of course, it'd be even better if diff tools were more aware of the format/language of the code being diff'd, at which point it'd be able to say "new element added to foo" instead of reporting on a bunch of reflowed lines.