Python String Sucks
Python got the worst design for string. Let me explain.
# python string syntaxes 'APOSTROPHE' "QUOTATION MARK" """triple QUOTATION MARK""" '''triple APOSTROPHE''' r'raw APOSTROPHE' r"raw QUOTATION MARK" r"""raw triple QUOTATION MARK""" r'''raw triple APOSTROPHE'''
Issues of String Syntax Design
different string syntax in a programing language, is to solve the problem of:
- Prevent the delimiter char happening in the text.
- The issue of dealing with literal unprintable ASCII Characters such as horizontal tab, line feed, form feed, carriage return, null, etc.
- The issue of representing unprintable chars in Unicode, such as right to left marker char.
- Embed variables in the string.
Common Solution
Now, most languages solve these by:
- Have backslash escape sequences, inherited by the force of convention from the C fuckheads. (the escape sequences, creates non-trivial parsing complexity, which in turn, makes inter-process communication difficult. e.g. passing a complicated regex string as arg from emacs to a shell program.).
- Have two string syntax: interpreted and literal. Interpreted is delimited by QUOTATION MARK. Literal is delimited by APOSTROPHE. 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).
Python String Syntax Design Idiocy
now, the way python tried to solve this, is:
Equivalent Delimiters Idiosy
first, it has both APOSTROPHE and QUOTATION MARK char as equivalent delimiters, for its so called "short string"
fuck.
And this python short-string fuck, 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 APOSTROPHE or QUOTATION MARK, which in real life often contain both. So the python short-string syntax is one idiotic fuck.
Half-Solution of Triple Quote
Then, python the guido von rossum idiot, created triple quote, to solve the arbitrary big string problem. This is idiotic because, the text may contain python code involving triple quote, so you got a problem. it is inferior to the here-string,
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. (addendem, python added f-String to fix this problem.
〔see Python: f-String (Format, Template)〕
)
What guido should've done, is in python 3, make the APOSTROPHE delimeter as raw string
and rid of the r
raw string prefix.