• Andrew Gerrand's avatar
    godoc: make example code more readable with new comment convention · 11e113db
    Andrew Gerrand authored
    go/doc: move Examples to go/ast
    cmd/go: use go/doc to read examples
    src/pkg: update examples to use new convention
    
    This is to make whole file examples more readable. When presented as a
    complete function, preceding an Example with its output is confusing.
    The new convention is to put the expected output in the final comment
    of the example, preceded by the string "output:" (case insensitive).
    
    An idiomatic example looks like this:
    
    // This example demonstrates Foo by doing bar and quux.
    func ExampleFoo() {
            // example body that does bar and quux
    
            // Output:
            // example output
    }
    
    R=rsc, gri
    CC=golang-dev
    https://golang.org/cl/5673053
    11e113db
example_test.go 1.5 KB