Tom Ritchford
1 min readMay 27, 2020

--

Neither of these examples are good because they

break a thought in the middle!

I now use a program called Black that automatically reformats Python code in exactly one way — which involves doing as little breaking up as possible.

I was late to the party — Black was extremely popular before I even got to it. I soon found out why.

I don’t even have to try it out — it would reformat your code like this:

func = long_function_name(
var_one, var_two, var_three, var_four
)

If the code were longer, it would look like this:

func = long_function_name(
var_one,
var_two,
var_three,
var_four,
var_five,
var_six,
var_seven,
var_eight,
var_nine,
var_ten
)

Here, there’s less breaking up because it’s one column. Variables are always either one row, or one column.

Initially I thought it was crazy. Then I noticed how much more readable my code got. Now I’m a convert.

(I only change Black’s behavior in two ways — I use single quotes ' instead of double " because, hey, less typing. And I keep all my files at 79 columns, strict PEP 8, just because I like the discipline on myself. I wouldn’t force that on others…)

--

--

Responses (1)