Help read 'string'

Hi, from https://learnxinyminutes.com/docs/go/
what is ‘string’ in here?
func (p pair) String() string {

string is the type string. In

func (p pair) String() string {

it is the return type of the function String.

But this is all written in the code on the page you’ve linked to:

// Define a method on type pair. Pair now implements Stringer because Pair has defined all the methods in the interface.
func (p pair) String() string { // p is called the "receiver"
    // Sprintf is another public function in package fmt.
    // Dot syntax references fields of p.
    return fmt.Sprintf("(%d, %d)", p.x, p.y)
}

Looking at the excerpt and then at the blog post itself, I think that post is anything but a good introduction to Go. It is VERY condensed, so unless you already know a lot of other programming languages and therefore are able to deduce what a given expression in this post might possibly mean, you quickly get lost.
Moreover, there are a couple of forward references that makes the post even harder to grok.

I suggest taking the Go Tour instead, it provides a good first peek into the language.

3 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.