by boxed · 1y ago · 0 comments
That doesn't automatically mean it's a good idea in C++, knowing C++ there are gonna be a whole lot of gotchas which aren't in Python, but it means that, at least in my opinion, how F-strings worked in Python is an argument in favor of them rather than against them.
Swift strings have ONE string. Just a single clean design that does all of that. With a simple set of rules.
You might be on your own here.
To quote myself:
Yea, f-strings are nice. But f-strings, r-strings, \ escaping, {{ escaping, ''' strings? Horrible.
Swift strings have ONE string. Just a single clean design that does all of that. With a simple set of rules.
Swift has just 1 string.
Look up Swift strings. Python has 4 types of string literals. Swift has 1. And they are BETTER and more powerful. Cleaner.
So compared to Python, string interpolation is always "on" and doesn't need an f-prefix. Because it uses the string escaping syntax, it doesn't have to take over a regular character like {, which requires {{ escaping.
Swift doesn't have raw strings and normal strings. Swift has ONE syntax:
{#n}"string {#n}\(interpolation)"{#*n}
Where n can be zero or more. So let's recap:
1. ONE rule for start/end/escape prefix: A number of # that has to match. 2. ONE rule for escape: \.
I do Python full time and I wouldn't consider switching to Swift, but the string situation is horrible compared to Swift.