luminousmen / luminousmen.com

2 stars 0 forks source link

https://luminousmen.com/post/my-unpopular-opinion-about-black-code-formatter #5

Closed utterances-bot closed 3 weeks ago

utterances-bot commented 4 years ago

My unpopular opinion about black code formatter - Blog | luminousmen

In this post, I will try to gather all my thoughts on the topic of automatic code formatting and why I personally don't like this approach

https://luminousmen.com/post/my-unpopular-opinion-about-black-code-formatter

sobolevn commented 4 years ago

I agree with you on this one. In my opinion, black is a great tool if you have a big messy codebase that one ever cared to format. Then you can apply black once to format this codebase to be uniform. And that's it.

I consider other use-cases harmful. Linters are way better in enforcing consistency and sharing knowledge than auto-formatters. I also like the idea that a good linter help you to develop a healthy habit to write good-formatted code all the time. Instead of auto-formatters that promotes "write however you want" philosophy.

Here's our statement on auto-formatters in wemake-python-styleguide: https://wemake-python-stylegui.de/en/latest/pages/usage/integrations/auto-formatters.html

akaihola commented 3 years ago

If you don't want the whole code base to be reformatted in one commit, you can use Darker to only apply Black reformatting to lines modified since the last commit (or since e.g. a given branch).

Running Darker can be bound to a shortcut in an IDE – it's quite nice to quickly write code without caring at all about formatting and then let Black quickly reformat just that part.

sobolevn commented 3 years ago

Hi, @akaihola! It is great to hear from you! django-split-settings is doing great! 👍

I will check Darker out!

Czaki commented 2 years ago

Black is great tool for opensource projects which are open for new, inexperienced contributors. In projects which I meet to many time was waste on fixing code formatting in PR than on reviewing changes in code. But if we talk about project developed by same group of experienced users you may expect that they will not push wrong formatted code.

Czaki commented 2 years ago

@sobolev after read https://wemake-python-stylegui.de/en/latest/pages/usage/integrations/auto-formatters.html I have two remarks.

Now black add trailing comas, not remove them. Also line length you may configure, In many projects I see line length set to 120 for both black and flake8.