Skip to content

Instantly share code, notes, and snippets.

@DuckSoft
Last active July 3, 2017 07:36
Show Gist options
  • Save DuckSoft/1007782d96518ecb212adc2de19acb07 to your computer and use it in GitHub Desktop.
Save DuckSoft/1007782d96518ecb212adc2de19acb07 to your computer and use it in GitHub Desktop.
proposal: introducing a new raw string literal

Background

It came to me when I was writing something like this:

package main
import "fmt"

func main() {
    fmt.Println(`----------------
Demo Program
----------------
 - foo
 - bar
----------------`);  
}

which prints:

----------------
Demo Program
----------------
 - foo
 - bar
----------------

but, why not make it like this one?

    fmt.Println(```
----------------
Demo Program
----------------
 - foo
 - bar
----------------```);  

or this one?

    disptext := ```
----------------
Demo Program
----------------
 - foo
 - bar
----------------```
    fmt.Println(disptext)

Proposal

To introduce a new literal for raw string, where triple backquote is used to surround a raw string area, whose first linebreak is ignored:

    ```
this is a raw string
lol```

This is equivalent to:

    `this is a raw string
lol`

or simply:

    "this is a raw string\nlol"

The only difference between the new literal and the old 'backquote-raw string-backquote' literal is that, the new literal stripped out the first linebreak from the raw string, making it easier to write multiline text, just as the example provided in section "Background".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment