What does HackerNews think of black?

The uncompromising Python code formatter

Language: Python

#70 in Hacktoberfest
#61 in Python
Python formatter Black: https://github.com/psf/black

By using Black, you agree to cede control over minutiae of hand-formatting. In return, Black gives you speed, determinism, and freedom from pycodestyle nagging about formatting. You will save time and mental energy for more important matters.

Black makes code review faster by producing the smallest diffs possible. Blackened code looks the same regardless of the project you’re reading.

Python does have an auto-formatter [6], so clearly indentation doesn't prevent that.

> Also, forget a brace in your program, just one, and the compiler can tell.

Should we duplicate every character, so the compiler can tell if you leave one out? This is not a radiation-hardened quine [7].

> editor settings can make it much easier to break things with significant whitespace.

Then use an editor which doesn't.

> Selecting all code contained in a brace or a parents is so much easier (in vim the % movement) than if you have to walk lines.

I have a plugin for Neovim that adds indentation-based motions. The implementation is trivial.

[6] https://github.com/psf/black

[7] https://codegolf.stackexchange.com/questions/57257/radiation...

It's funny that geohot/tinygrad chooses to not meet the PEP8 standards [0] just to stay on brand (<1000 lines). Black [1] or any other python autoformatter would probably 2x the lines of code.

[0] https://peps.python.org/pep-0008/

[1] https://github.com/psf/black

> We still don't have format selection

And you never will. From https://github.com/psf/black:

Black is the uncompromising Python code formatter. By using it, you agree to cede control over minutiae of hand-formatting. In return, Black gives you speed, determinism, and freedom from pycodestyle nagging about formatting. You will save time and mental energy for more important matters.

This is why the good lord gave us: https://github.com/psf/black

Import line is actually improved with this commit. LGTM, ship it.

We now return to your regularly scheduled bikeshedding.

Black is a tool that can reformat Python code. It's remarkable for it's lack of configuration.

https://github.com/psf/black

> that's because the UX for github PRs sucks. Use Gerrit instead. It's not as pretty but it's super productive.

That won't affect the quality of what people find and comment about.

> that's not a problem caused by code review, it's caused by people who don't know how to work with others (or otherwise simply refuse to). to the degree that the code review process shines a light on this, that's good news, because that's a people problem that should be fixed.

You say that like fixing people is an easy thing to do. It's the hardest thing to do. And the fact I've seen this at so many companies/teams leads me to believe that it's an extremely common thing.

> when you look at a code review and you see problems in what's there, catching them in the code review is great, because that means less chance of having to fix it later. > if you see a code review and nothing's wrong with it, you just approve it. sometimes you can note things as "nits", meaning, fine for now but maybe next time do it this way.

Yea... Those aren't getting done at 9/10 companies. They're getting ignored.

> syntactical style and formatting should be automated, if not with tooling that actually rearranges the code in that way (e.g. [black](https://github.com/psf/black) for Python) then at least including well tuned linter rules. We use black, my own zimports tool for sorting imports, flake8 with four or five plugins as well as "black check", so we spend exactly zero time dealing with anything to do with style or code formatting, including having to even type any of it. if people are fighting over code style then there need to be tools that lock all of that down so there's no disagreements.

Yea, we have those, I still get asked for stupid ass code style changes at every company for the last 8-years. Why? Because people can spot them and understand them. But can't code review for shit. They can't understand the idioms for the programming language, they can't understand how certain paradims work, they don't pay attention to root causes of bugs, they don't know how to design a database, they don't pay attention to performance, etc. I would say 80% of the industry can't code review for crap. And that is the biggest problem and because they can't do that all the other problems are just symptons.

> I work on the Openstack project and that is where I learned to do code review with Gerrit, it is completely essential for large projects and is an enormous productivity enhancement. Decades ago before CVS was even invented, the notion of using source control seemed crazy to me. That position was obviously insane, even though we were stuck using Visual Source Safe at the time. That's how it feels to me to be doing a real project today without code review and formatting tooling in place. Like even for myself, if working alone, for a large project with lots of changes I still use a code review tool, just to review myself.

This doesn't dispute or refute my point. It merely says in some cases it's used well. It doesn't remove the fact that majority of the time it's cargo cult and the majority of people who code review can't code review for crap or the fact that a high percentage of people just skim code review.