Re:Still in love with Rust
by growtofill on Thursday November 22, 2018 @03:27AM
(#18508657)
Doesn't Python have an autoformatting tool like gofmt or Prettier?
[ Parent
| on HN ]
Black (The uncompromising Python code formatter) is all the rage atm.
Yes. Most of the projects now use black https://github.com/ambv/black
Re:Still in love with Rust
by quietbritishjim on Thursday November 22, 2018 @04:10AM
(#18508830)
The problem that black had last time I saw it on hacker news is that it only inserts whitespace. Unlike braces-and-semicolon languages, that is sometimes not enough to format code well. For example, given the following line:
x[1][4] = a[2] + b[4]
Black will format like either of these: x[1][
4] = a[2] + b[4]
x[1][4] = a[
2] + b[4]
But not like either of these, unless you insert the brackets yourself: x[1][4] = (
a[2] + b[4])
x[1][4] = (a[2]
+ b[4])
Maybe this sounds like just one little problem but I think it's a fundamental flaw. I have seen the result of a Python formatter (not Black but had the same problem) applied to a couple of files and it's a total mess. I'd take inconsistent column widths over that any day. I asked the creator of black about it and he was pretty dismissive.I use yapf and in such cases backslashes work fine:
x[1][4] =\
a[2] + b[4]