5 ms·
Double quotes also have drawbacks, visual noise and the doubling of keypresses required on the most common keyboard layouts.
by mixmastamyk 8y ago
Double quotes also have drawbacks, visual noise and the doubling of keypresses required on the most common keyboard layouts.
- ambivalence 8y agoYou can still type single quotes. You have a tool to convert that for you. The visual noise complaint is interesting. Do you also consider the letter W to be more noisy than the letter V? Should we discourage the use of noisy letters in the alphabet?
- mixmastamyk 8y agoYes, why www. was dropped, and quotes are used everywhere in most Python code. The triple doubles for doc strings are the worst example, though I have no illusions pep8 will be changed any time soon.
- davnn 8y ago> The visual noise complaint is interesting. I thought the same. I guess you could just modify your programming font to make the double quotes really tiny :)
- zestyping 8y agoA double-quote is more noisy than a single-quote, and W is more noisy than V. The difference is that " and ' are equally usable options in the context we're talking about. Quotes are very common, so the visual noise adds up when your screen is full of quote marks. Given that they mean the same thing, and one is both harder to type and harder to read, it makes sense to prefer the other.
- mixmastamyk 8y ago> Given that they mean the same thing, and one is both harder to type and harder to read, it makes sense to prefer the other. Nailed it.
- prawl 8y agoA double quote is in no way harder to read. Only on Hacker News.
- abiox 8y agothis seems a bit reductive.
- woolvalley 8y agoEh, many programming languages use double quotes for strings, and single quotes for singular characters. Languages that can use single quotes for strings that I know of are ruby and python.
- ciupicri 8y agoAlso Pascal and SQL.
- samatman 8y agoLua, and there are others. I favor double quotes for this same reason even when single quotes are allowed. I'd like «guillemets» but that's going to have to be self-serve...
- spc476 8y agoI use single quotes when the string in question is used like an enumeration: set_color('black','white') And double quotes for strings meant to be read by a human: print("Hello there. How are you?") And an example with both forms: syslog('warning',"unit %s spin rate %f too low",u,rate) For me, it's an indication of how I expect the string to be used.
- Inityx 8y agoAnd even then, Perl and Ruby (heck, even Bash) have a semantic difference between double- and single-quoted strings. The only other popular general-purpose languages where they're synonymous are PHP, JavaScript, and Lua.
- ComputerGuru 8y ago>The only other popular general-purpose languages where they're synonymous are PHP, JavaScript, and Lua. PHP does treat single and double quotes differently. Contents of single quotes strings are not parsed for variable substitution.
- ComputerGuru 8y ago
- ben509 8y agoI agree about the noise, but, it's much easier to work with. raise FooException("Can't load bar") works, as does f"The flange is elevated by {flange['spronge']} degrees of spronge."
- mixmastamyk 8y agoGoes both ways, sometimes there's text to quote: raise KeyError('"%s" not found.' % name) f'The flange is elevated by {flange["spronge"]} degrees of spronge.' I don't normally use many contractions or possessives in my code, but am willing to admit it happens occasionally.
- zestyping 8y agoYep, that's why I like how repr() does it. Guido solved this nicely a long time ago :)
- rapind 8y agoThe "visual noise" makes it clearer the me that it surrounds a block of text, so I don't buy this. Double quotes are also the convention in english to delineate a literal, so I would argue it's more obvious. I'll grant you keyboard presses though. There's an obvious advantage to single quotes here, but consider why this is the case. To make the use of "apostrophe" more efficient since it appears far more often than a double quote in english. I suppose it's pragmatic to leverage this advantage in code where string quoting is extremely common... Perhaps double quoting is a bias I've developed writing code, but I suspect it's actually a bias I carried over from reading and writing english and what simply seemed more obvious. Language design than supports both makes me crazy. Pick one and enforce it!