Skip to content

Documentation: func String() description in "Effective Go" is wrong #1796

@gopherbot

Description

@gopherbot

by christopher.helck:

Document "Effective Go" under the Printing section shows how to write String()
function for object T:

func (t *T) String() string {
    return fmt.Sprintf("%d/%g/%q", t.a, t.b, t.c)
}
fmt.Printf("%v\n", t)


This is incorrect, the function should not take a pointer, instead it should be written
as:

func (t T) String() string {
    return fmt.Sprintf("%d/%g/%q", t.a, t.b, t.c)
}
fmt.Printf("%v\n", t)


The tutorial has the same issue, but the specification is correct.

I checked to see how String() method is written in packages. See
http://golang.org/src/pkg/image/geom.go?s=1791:1825#L69 for an example.

As a beginner I found this hard to debug.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions