News for hackers. Stuff that matters.
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?
Re:Still in love with Rust by eirki on Thursday November 22, 2018 @03:57AM (#18508776)
Black (The uncompromising Python code formatter) is all the rage atm.

https://github.com/ambv/black

Re:Still in love with Rust by sametmax on Thursday November 22, 2018 @04:00AM (#18508786)
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.
Re:Still in love with Rust by Rotareti on Thursday November 22, 2018 @09:19AM (#18510098)
I use yapf and in such cases backslashes work fine:

    x[1][4] =\ 
        a[2] + b[4]
Re:Still in love with Rust by dhuramas on Thursday November 22, 2018 @03:55AM (#18508764)
Re:Still in love with Rust by baq on Thursday November 22, 2018 @03:55AM (#18508766)
there's autopep8 and a few other tools but none are considered idiomatic.