[Python-ideas] String interpolation for all literal strings

Andrew Barnert abarnert at yahoo.com
Thu Aug 6 02:45:59 CEST 2015


On Aug 5, 2015, at 17:26, Chris Angelico <rosuav at gmail.com> wrote:
> 
> On Thu, Aug 6, 2015 at 10:13 AM, Andrew Barnert <abarnert at yahoo.com> wrote:
>>> Whether or not it's good for string literals to support interpolation,
>>> though, I'm not sure about. The idea that stuff should get
>>> interpolated into strings fits a shell scripting language perfectly,
>>> but I'm not fully convinced it's a good thing for an applications
>>> language. How shelly is Python? Or, what other non-shell languages
>>> have this kind of feature? PHP does (which is hardly an
>>> advertisement!); I can't think of any others off hand, any pointers?
>> 
>> Guido's specific inspiration was Swift, which is about as "applicationy" a language as you can get.
> 
> Thanks. If anyone else wants to read up on that:
> 
> https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/StringsAndCharacters.html
> 
> I poked around with a few Swift style guides, and they seem to assume
> that interpolation is a good and expected thing, which is promising.
> No proof, of course, but the converse would have been strong evidence.

I personally love the feature in Swift, and I've worked with other people who even considered it one of the main reasons to switch from ObjC, and haven't heard anyone who actually used it complain about it. And there are blog posts by iOS app developers that seem to agree. Of course that's hardly a scientific survey. Especially since ObjC kind of sucks for string formatting (it's basically C90 printf with more verbose syntax).

I have seen plenty of people complain about other things about Swift's strings (strings of Unicode graphemes clusters aren't randomly accessible, and the fact that regexes and some other string-related features work in terms of UTF-16 code units makes it even worse), but not about the interpolation.


More information about the Python-ideas mailing list