title: Methods and receivers in Go
body: <p>I have problems understanding methods and receivers in Go. Let's say we have this code:</p>
  
  <pre><code>package main
  import ("fmt"; "math")
  type Circle struct {
      x, y, r float64
  }
  func (c *Circle) area() float64 {
      return math.Pi * c.r * c.r
  }
  func main() {
      c := Circle{0, 0, 5}
      fmt.Println(c.area())
  }
  </code></pre>
  
  <p><code>(c *Circle)</code> in the definition of the <code>area</code> function is said to be a <em>receiver</em> and in the <code>main</code> we can call area and pass <code>c</code> by reference without the use of pointers. I can edit the code to the following and it works the same way:</p>
  
  <pre><code>package main
  import ("fmt"; "math")
  type Circle struct {
      x, y, r float64
  }
  func circleArea(c *Circle) float64 {
      return math.Pi * c.r*c.r
  }
  func main() {
      c := Circle{0, 0, 5}
      fmt.Println(circleArea(&amp;c))
  }
  </code></pre>
  
  <p>Now is this just a syntactical difference between the two snippets of code or is there something structurally different going on on a deeper level? </p>