Skip to content

Instantly share code, notes, and snippets.

@DevAndArtist
Last active May 22, 2017 08:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DevAndArtist/0c95f8549bb7d97387b360b4cfb3e09e to your computer and use it in GitHub Desktop.
Save DevAndArtist/0c95f8549bb7d97387b360b4cfb3e09e to your computer and use it in GitHub Desktop.
print("\"text\" \"text\" \"text\" text text text text text text text text text\ntext text text text text text text")

Allow:

print("
  \"text\" \"text\" \"text\" text text text text \
  text text text text text\n
  text text text text text text text
  ")

// shorter alternative:
print("\"text\" \"text\" \"text\" text text text text \
  text text text text text\n
  text text text text text text text")

Extend to:

print("""
  "text" "text" "text" text text text text \
  text text text text text
  text text text text text text text
  """)

// shorter alternative:
print(""""text" "text" "text" text text text text \
  text text text text text
  text text text text text text text""")

Ban the following forms:

// #1
"
abc
def"

// #2
"abc
def
"

// #3
"""
abc
def"""

// #4
"""abc
def
"""

Trailing \ provides two functionalities:

  1. Hard wrapping a long line.
  2. Boundary for trailing whitespace characters.

(If no trailing whitespace character are presented, then we can ommit the \)

// #1
"
a\
b\
" == "ab"

// #1.1
"
a
b
" == "ab"

// #2
"
a \
b \
" == "a b "

// #3
"
 c \
 d \
" == " c  d "

// #3.1
" c  \
d " == " c  d "

// #3.2
" c  \
  d " == " c  d "

// #4
"""
a \
b 
c\
""" == "a b\nc"

// #4.1
"""
a \
b 
c
""" == "a b\nc"

// #5
"""
 a \
 b 
 c
""" == " a  b\n c"

// #5.1
""" a  \
 b 
 c""" == " a  b\n c"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment