3 ms·
It is only my personal opinion but I find the f-strings to be conceptually bad: It might be a little bit easier to writer, but now you have magic and also code
by greatgib 6y ago
It is only my personal opinion but I find the f-strings to be conceptually bad:
It might be a little bit easier to writer, but now you have magic and also code that is mixed within what should be simple strings. It is so easy to have suprising bad side effects because some operation would have been hidden in strings.
- dijit 6y agoIt makes sense when you consider other string methods. r"" strings for raw representation (this breaks most syntax highlighters though) u"" for unicode string b"" for bytes string. f"" would totally fit as a "formatted string". (R&B strings were available in python2, for context).
- xorcist 6y agoThey are more like templates than strings, which makes things like internationalization unnecessarily hard. Personally I find the use case between simple %-interpolation of dumb strings and full blown templates pretty small.
- pydry 6y agoI agree but it's not a popular opinion. I liked the ability to put semi-complex anonymous expressions in format and reference them with {}. If you did this it was still be obvious what was going on without having to create variable names like comma_separated_list_of_emails. Technically this is possible in f strings but it leads to an escaping mess. You wouldn't want to put a comprehension with a ','.join in there, for example. Even when you did use variable names (e.g. "{addr_list}...".format(addr_list=...") you could safely use shorter names because the scope was tighter.
- whalesalad 6y agoSo easy? I’ve never created a side effect in my life with f-strings. The same could be said about virtually any feature of any language. Why would you want to impose artificial constraints on yourself? I really dislike the argument “people will hurt themselves, let’s go back to the old way“