Hacker News new | past | comments | ask | show | jobs | submit login

This is a great tool. I wish there was some settings to use single quotes instead of double quotes.



Funny that this is a common reaction against opinionated tools: "I wish there was a configurable option to apply my opinions"

But the whole idea is that you should learn to suppress your ego and let the tool be the one dictating stylistic choices...

Like the sibling comment mentions:

Dusty Phillips, writer:

"Black is opinionated so you don’t have to be."


That made me wonder, so I went and tested edge cases, like "abc\"d\"ef", which black quite properly converts to 'abc"d"ef'. So it does use single quotes where appropriate.


I understand that. And this is what I like in Black. But the single quotes thing is really up to debate. When you use it with other tools such as flake8 or pylint, you have to disable a bunch of things to make them work together because no one agrees on this point.


I'm not a full time Python dev so I won't (can't) get into what choice has more merits. But there is this:

https://black.readthedocs.io/en/latest/the_black_code_style/...

Seen from outside, I think the double quotes are just the natural form of strings in lots of other places, at least in those that come from the same family than C (C++, Java, C#, Rust, just to name a few)

Also Prettier.js (which I'd call the "Black of JavaScript") also settled on double quotes. So we're left with a de facto consensus across programming languages as a whole, which kind of feels nice.


> When you use it with other tools such as flake8 or pylint, you have to disable a bunch of things to make them work together

Using Flake8 with Black requires only two configuration options [1], while Pylint requires three [2]. If you prefer to use Black with --line-length 79, then it's down to a single configuration option for Flake8 or two for Pylint.

[1]: https://black.readthedocs.io/en/latest/guides/using_black_wi...

[2]: https://black.readthedocs.io/en/latest/guides/using_black_wi...


You can have some basic configurable stuffs in an opinionated tool though, see Prettier. It allows tab/space, quote style, line length etc., to be modified.


Prettier has some options, but they are not happy about it, it's just how things happened and now cannot be "solved", i.e. remove them, albeit they would love being able to do that:

https://prettier.io/docs/en/option-philosophy.html


"My opinion is the correct one"

- Author of some tool


“No opinion is correct, so we should stop wasting time debating it.”

- advocates of code formatters


"let's everyone stop debating it the exact moment after you adopt my preferences"


There is: -S, --skip-string-normalization Don't normalize string quotes or prefixes.


IIRC, the -S only avoid single quotes to get switched to double quotes. What I meant was allowing Black to switch double-quotes to single quotes automatically.


Try nero from PyPI instead, I’ll update it to this stable release shortly.


There’s also “blue” which I’m the author of and looks similar: https://pypi.org/project/blue/ would love to get your help and thoughts in the issue tracker or by email.


What did you have in mind?


There probably is, if you use another formatter that isn’t Black.


I like yapf.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: