Skip to content

Instantly share code, notes, and snippets.

@drewlesueur
Created December 5, 2010 10:31
Show Gist options
  • Save drewlesueur/728999 to your computer and use it in GitHub Desktop.
Save drewlesueur/728999 to your computer and use it in GitHub Desktop.
The hello world of Object Oriented Prorgramming in Go
// run this code at http://golang.org/
package main
import "fmt"
type Person struct {
age int
name, fav_band string
}
// the 'that' is like the 'this' you would see in other languages
func (that *Person) getOlder() int {
that.age = that.age + 1
return that.age
}
func main() {
person := new(Person)
// or var person Person
person.age = 7
fmt.Println(person.age)
person.getOlder()
fmt.Println(person.age)
}
@drewlesueur
Copy link
Author

Thanks to tutorial at http://research.swtch.com/2009/12/go-data-structures-interfaces.html

Also see the aswesome functional programming tutorial at http://livingcode.org/2009/11/13/go-language-and-functional-programming.html

Any suggestions?

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