Py-dea: Streamline string literals now!

Rick Johnson rantingrickjohnson at gmail.com
Tue Dec 27 22:49:12 EST 2011


Hello folks,

In a recent thread i stumbled upon an epiphany of sorts concerning
Python string literals, with implications that trickle down to all
forms of string literals used in general programming, since, for the
most part, the syntax is virtually the same!

For all our lives we have been excepting a standard for string
literals that is, quite literally, overkill. It seems all along the
syntax has been flawed, however, we have been totally unaware... until
now!

*[A brief history lesson]*

Python offers two main styles of delimiting string literals:
 * single "leading and trailing" double, or single quote chars.
 * triple "leading and trailing" double, or single quote chars.

The single leading group is intended for one line literals whereas the
triple is intended for multi-line literals.

Now, in my initial days of Python-ing, i thought this was a great
system. Unlike most languages that require a programmer to concatenate
strings over and over again, python "seemed" to solve the multi-line
issue -- but there is a greater issue!

*[Current Issues]*

The fact is...even with the multi-line issue solved, we still have two
forms of literal delimiters that encompass two characters resulting in
*four* possible legal combinations of the exact same string! I don't
know about you guys, but i am not a big fan of Tim Towtdi.

But the problems just keep adding up. There is also the issue of
escape sequences; which i have always found to be atrociousness noisy.
Everyone who has had to deal with double escapes in regexps raise your
hand. The frowns are deafening.

The simple fact is: The current syntax for string literals is not only
deficient, it is bloated, noisy, and confusing!

*[Solution]*

I believe that with the ubiquitous-ness of syntax highlight, string
literals only need one delimiter.  In the old days (before syntax
highlight was invented) i could understand how a programmer "might"
miss a single (or even a triple!) closing delimiter; but those days
died with the king.

My proposal is to introduce a single delimiter for string literals. A
new string literal that is just as good at spanning single lines as it
is spanning multiple lines. A new literal that uses widely known
markup tag syntax instead of cryptic and noisy escape sequences. And
finally, a *literal* that is worthy of the 21st century.

Thank You.



More information about the Python-list mailing list