Re:Black – Uncompromising Python code formatter
by photonios on Friday May 17, 2019 @12:25PM
(#19941062)
You could configure your IDE to re-format files into your favorite format and just have a pre-commit hook that formats them back into the official format. That's how I work. No arguments about style and formatting, yet I get to make the code look how I personally prefer it.
[ Parent
| on HN ]
Re:Black – Uncompromising Python code formatter
by a1369209993 on Friday May 17, 2019 @01:26PM
(#19941680)
No, we can't. My (and, by the sound of it, CrLf's) favorite format relies on information that your pre-commit hook has artificially removed from the code. Eg:
munge(gidget,
thing1,thing2,thing3);
cmplt(dtypeA,valueA,
dtypeB,valueB);
(Most cases are more subtle (and thus less amenable to "oh, you just need to build a complete static type checker into the formatter") than this, but I wanted an obvious example.)
Re:Black – Uncompromising Python code formatter
by RussianCow on Friday May 17, 2019 @02:11PM
(#19942102)
It seems like the signature of the functions should be different, especially the second example. I would have written the cmplt function to take tuple pairs:
cmplt(
(type_a, value_a),
(type_b, value_b),
)
That's much more clear about the relationship between each pair of values either way, and would get formatted nicely by Black.
Re:Black – Uncompromising Python code formatter
by edflsafoiewq on Friday May 17, 2019 @03:06PM
(#19942495)
No it wouldn't; black will put that all on one line if it can. The semantic information in vertical space is lost.
A better example is a matrix laid out as a grid, which auto-formatters always destroy
mat3x3(
0, a, -b,
-a, 0, c,
b, -c, 0,
)
Re:Black – Uncompromising Python code formatter
by a1369209993 on Friday May 17, 2019 @03:15PM
(#19942572)
To be fair, I suspect RussianCow would write that as something like:
mat3x3(
rowvec3( 0, a, b),
rowvec3(-a, 0, c),
rowvec3( b,-c, 0),
)
Which is probably better, especially with tuples instead of struct{Scalar[3]}. Doesn't fix mat3x3(( 0, a, b),(-a, 0, c),( b,-c, 0))
, though.
Re:Black – Uncompromising Python code formatter
by a1369209993 on Friday May 17, 2019 @03:00PM
(#19942458)
Sorry, should have clarified: my example was written in C[0][1]; cmplt is something like (Dtyp* ,Dval* ,Dtyp* ,Dval* ), which is what I was alluding to with "just need a type checker". Also, in the code I anonymised that from, cmplt and munge are imported (well, #included) functions from a different library.
0: which doesn't have tuples anyway; you could use structs, but it doesn't really work well in context/practice.
1: I don't use python frecently enough to have ready examples of autoformatter stupidity on hand for it.
Re:Black – Uncompromising Python code formatter
by zestyping on Friday May 17, 2019 @07:02PM
(#19944429)
It would also have been a better way to define the function, in Python 2.
def cmplt((type_a, value_a), (type_b, value_b)):
return ...
I was sad when they removed argument unpacking in Python 3. I thought it was a really elegant feature of the language.
Re:Black – Uncompromising Python code formatter
by joshuamorton on Friday May 17, 2019 @07:23PM
(#19944527)
Pretty much no one used it, and it was....weird.
what do you think the result of
def cmplt((type_a, value_a), (type_b, value_b)):
return locals()
is? Now granted, you shouldn't do that, but what you think it is? a dict with 4 keys, right? {'type_a': ..., 'value_b': ...}.That's wrong. It has those four keys, and two more: '.0' and .1', whose values are the packed tuples.
!?!?!
There is no such thing as "my favorite format" in that sense. Also, I don't mind reading code in other people's "favorite format" nor do I have any problem in following another person's style if that's the style agreed upon by the team.