.feed-links {display:none !important;} -->

Black, the uncompromising python code trainer

 black

Black, what is it?

Black is a python code trainer . Formatting your code is essential, as we saw in the previous chapter, writing your code must respect a certain number of visual rules. For example, the code must not exceed 79 characters.

It's essential ... but it's a waste of time.

To not waste this time, this precious time, delegate this task to a program! ... And this program is Black , your new best friend.

Why is Black so good?

It is always amazing how much we prefer his code to that of others. We have our little habits; and when we see the code of another developer, the first thing we see is not the quality of its content or the intelligence that it was able to put in a script coded in 10 lines whereas d 'others would have done it in 20. No. What we see first is that it has exceeded the maximum of 79 by 1 character, and there is a newline that was not needed.

We look at the form before the substance. It's like that.

Black will homogenize the shape of your code.

After finalizing your Python code , you run the Black mill and there, as if by magic, your code will be perfectly formatted. No more criticism of the form can be heard. The reader of your code will finally be able to devote himself directly to the content of your code.

Time saving

Beyond all the psychological and regulatory aspects, running Black at the end of your code will save you a lot of time both writing and reading. You will be used to the form, and if you work in a team of developers it is great fun to read code in a format you are familiar with.

Install Black

We use pip to install Black:

pip  install  black

Then in command line:

black  { your_file }

No comments:

Post a Comment