Python String Sucks
Python got the worst design for string. Let me explain.
# python string syntaxes 'single' "double" """triple double""" '''triple single''' r'raw single' r"raw double" r"""raw triple double""" r'''raw triple single'''
Diff string syntax in a programing language, is to solve the problem of:
- Prevent the delimiter char happening in the content.
- The issue of dealing with literal unprintable ASCII chars such as horizontal tab, line feed, form feed, carriage return, null, etc.
- The issue of representing unprintable chars in ASCII and Unicode, such as right to left marker char.
- Embed variables in the string.
Now, most lang solve these by:
- Have backslash escape sequences, inherited by the force of convention from the C faakheads. (the escape sequences, creates endless problems).
- Have two string formats: interpreted and literal. Interpreted is delimited by double quote. Literal is delimited by single quote. Interpreted means variable can be embedded, and escape sequence is interpreted. Literal is no interpretation. This began with perl. spread to php, ruby, PowerShell.
- By having a so-called here-doc or here-string syntax, which basically is random char sequence used as the string delimiter. (very good).
now, the way python tried to solve this, is:
first, it has both apostrophe and double quote char, as equivalent delimitors, for its so called short string faak. And this python short-string faak, cannot have literal line return.
This is a bad design. Because having 2 syntax to do the same thing, and they are essentially the same, except if the string contains a single or double quote, which in real life often contain both. So the python short-string syntax is one idiotic faak.
Then, python the guido von rossum idiot, created triple quote, to solve the arbitrary big string problem. This is idiotic because, it is inferior to the here-string, cuz ur string content could contain python code involving triple quote, u got a problem.
Then, the guido von rossum idiot, created raw string concept, with the r
prefix.
Trying to solve the non-issue of whether escape sequence should be interpreted as literal.
There is no mechanism to embed variable in string.
What guido should've done, is in python 3, make the single quote delimeter as raw string
and rid of the r
raw string prefix.