Go's formatter adjusts whitespace within a line and will add or remove blank lines, but it doesn't change line breaks and has no opinion on the maximum length of a line. Other formatters work differently.
Black – Uncompromising Python code formatter
31–40 of 251 posts
Re: Black – Uncompromising Python code formatter
#32Earlier quoted context omitted.
Why wait? I run black on all my new single-author projects.
i have my personal tics about formatting that i enjoy. As long as it’s just me, i’ll persist them.
Re: Black – Uncompromising Python code formatter
#33We use Black in a pre-commit hook for all our python code. It makes legibility and formatting a non-issue in the team. Yes it can look strange at first if you're not used to it, but after a while it makes formatting invisible (and it's odd reading non-black python). Would recommend.
Re: Black – Uncompromising Python code formatter
#34Against my better judgment I'll bite. I super dislike black's formatting, and I think it's really rare to actually see it in codebases. It wraps weirdly (sometimes not at all). I'd prefer to use yapf, but last I checked it still crashes on "f-strings". Here's a small example: basket.add({ apple.stem for satchel in satchels for apple in satchel }) Black formats this as: basket.add( { apple.stem for satchel in satchels…
Re: Black – Uncompromising Python code formatter
#35Having a standard is more important than the standard being excellent.
Re: Black – Uncompromising Python code formatter
#36Against my better judgment I'll bite. I super dislike black's formatting, and I think it's really rare to actually see it in codebases. It wraps weirdly (sometimes not at all). I'd prefer to use yapf, but last I checked it still crashes on "f-strings". Here's a small example: basket.add({ apple.stem for satchel in satchels for apple in satchel }) Black formats this as: basket.add( { apple.stem for satchel in satchels…
Re: Black – Uncompromising Python code formatter
#37Re: Black – Uncompromising Python code formatter
#38How do you enforce the use of a formatter in a project -- pre-commit hook? pre-receive hook? both? And is there a convention to put a specific dotfile at the project root to hint at your IDE/editor that it should use a certain tool for automatic formatting?
CI runs a linter and fails the build if the output is non-empty. PRs can't be merged unless the build passes on the branch.
Re: Black – Uncompromising Python code formatter
#39I've been using it for a few months now, but I don't really like it. It does remove quabbles about formatting, but I've personally never felt that as a problem and it just replaces them with constant frustration. I think code formatting is very important for readability, and I think many (subtle) choices about how to make a piece of code more readable are very subjective. These types of tools are just incapable to ma…
Are you sending unfortunate examples upstream? It's still beta, so it can be improved somewhat.
In the example I mentioned, I may sometimes choose to put a small dictionary initialization into a single line if it's just a detail, or may split it into multiple lines if it's important enough for someone reading the code to pay attention to it before going further.
This simply cannot be decided by an automatic formatter without it knowing the code's purpose which, for now, requires a human brain.
Someone mentioned elsewhere that automatic formatters remove the cognitive load of formatting code, but I argue that load is an intrinsic part of programming, because it is (for the most part) the effort of communicating to the next person that comes along.
Re: Black – Uncompromising Python code formatter
#40We use Black in a pre-commit hook for all our python code. It makes legibility and formatting a non-issue in the team. Yes it can look strange at first if you're not used to it, but after a while it makes formatting invisible (and it's odd reading non-black python). Would recommend.
how do you do this? do you have a jenkins server running that does the formatting? i would love to set this up because while i use black religiously i cannot for the life of me convince my boss get in the habit of using it (which is crazy because your commits are always fighting on whitespace).
(edit: black has pre-commit support [1], and it's easier than setting up and maintaining your own hooks IMO)
[1] https://github.com/python/black/blob/master/README.md#versio...