3 ms·
Close. But wrong. 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
by boxed 2y ago
Close. But wrong.
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.
- edflsafoiewq 2y agoYes it does, because normal strings aren't just a special case of raw strings when the number of #s is 0. The presence of #s change the string syntax. Otherwise you could as well say Python has one syntax, with optional f and r prefixes.
- boxed 2y agoNo, you can't. Because r/f changes and/or adds escape sequences, AND you can't have double-raw strings for example. In Swift there's 0, 1, 2, 3, 4, etc number of #. It's not raw strings at all! There's no -1 number of #. So for example to do regexes in python you normally use r-strings, to avoid \ escaping in the regex. In Swift you could do the same the opposite way: not by removing \ escaping, but by changing it to \#. And if you want to regex match for \#, you can do ##. And if you want to match for \## you can use ###, etc. There is always a clean escape where you can write the literal that you want to write. Unlike in Python where there is no escape (amusingly).
- edflsafoiewq 2y agoAh, I see. That is better.
- boxed 2y agoYea, it's a super nice system. It's such a pity that most language designers don't look at other languages before implementing stuff. I tried to warn the D guys not to make this exact mistake, but they didn't listen :/