5 ms·
I thought of another way to express this that might resonate better. What I like about the Black philosophy is that it wants to make code style _uninteresting_
by zestyping 8y ago
I thought of another way to express this that might resonate better.
What I like about the Black philosophy is that it wants to make code style _uninteresting_. People should think about other things, not formatting. That's a great goal. So it seems to me that the best style choice is the most _boring_ choice. The least creative, least novel way. It should try to avoid inventing new formatting algorithms.
What's the most boring way to format a string literal?
The way the language already does it. The way every Python programmer has already seen string literals formatted from the very first day they started typing things into a Python interpreter.
Even if half of us liked single-quotes and half of us liked double-quotes, you can guarantee that every Python programmer on the planet has seen and lived with strings that are formatted the repr() way, including the double-quote fans. You can't guarantee the opposite.
No one could fault you for doing it the repr() way. Blame Guido :) he made that choice decades ago, and everyone has already had to make their peace with it. It's a solved problem. For anyone writing a program that emits Python code, it's the default way to format a string. It's the least assailable option, and that's a good thing.
How does that sit with you?
- weberc2 8y agoI’m a Python programmer and I never had the perception that single quotes are more canonical in any capacity. I always felt that single quotes were for degenerates who didn’t realize that single quotes are most commonly used for chars by the broader programming community. ;)
- rndgermandude 8y agoI despise people using single quotes even more than people using tabs instead of space, emacs instead of vim or GNU-style indentation instead of... anything sane :D
- greyman 8y agoI used to use single quotes for dictionary keys and other constants, and double quotes for strings intended to be read by human. I read some article about it a considered it a good convention. Now I see it actually isn't a convention. :-) I switched to black just yesterday and overall I like it, still I miss a bit this distinction between single and double quotes.
- deleted 8y ago[deleted]
- vijucat 8y agoI've seen single quotes for chars vs. double quotes for Strings in Java, but in sh, it's "Strong Quoting with Single Quotes" vs. "Weak Quoting with Double Quotes": http://www.grymoire.com/Unix/Quote.html#uh-1 http://www.grymoire.com/Unix/Quote.html#uh-1 "When you need to quote several character at once, you could use several backslashes. This is ugly but works. It is easier to use pairs of quotation marks to indicate the start and end of the characters to be quoted. Inside the single quotes, you can include almost all meta-characters" So some of us associate single quotes with proper const strings, with no variable expansion, command substitution or other interpreter hanky-panky.
- heavenlyblue 8y agoI’ve always thought that double quotes are for degenerates who don’t pay attention to what a standard repr output is for strings.
- kuroguro 8y agoAnd I’ve always thought that triple quotes are for degenerates who... no, wait, nvm.
- heavenlyblue 8y ago... who can’t write self-explanatory code.
- nerdwaller 8y agoCode only captures the what and the how, comments for any complex routines can capture the why. Obviously overuse is probably a red-flag, but in my experience code alone doesn’t always capture enough context in any sufficiently complex system. I get your specific comment may be a bit sarcastic, given the ancestry - but I make this one more for younger developers I see that don’t always filter that ;)
- aldanor 8y agoYou don't have to press Shift as often to type string literals so it's a win, all other things being equal.