Top 1,000 Features Creators Resources Extensions Blog Explorer Download
GitHub icon

Go

< >

Go is an open source programming language created in 2009 by Rob Pike and Ken Thompson and Robert Griesemer.

#12on PLDB 15Years Old 1mRepos
Download source code:
git clone https://github.com/golang/go

Try now: Web ยท Riju ยท TIO ยท Replit

Go (often referred to as golang) is a programming language created at Google in 2009 by Robert Griesemer, Rob Pike, and Ken Thompson. It is a compiled, statically typed language in the tradition of Algol and C, with garbage collection, limited structural typing, memory safety features and CSP-style concurrent programming features added. The compiler and other language tools originally developed by Google are all free and open source.. Read more on Wikipedia...


Example from Compiler Explorer:
// Type your code here, or load an example. // Your function name should start with a capital letter. package main func Square(x int) int { return x * x } func main() {}
Example from Riju:
package main import "fmt" func main() { fmt.Println("Hello, world!") }
Example from hello-world:
package main import "fmt" func main() { fmt.Println("Hello World") }
// Hello world in Go package main import "fmt" func main() { fmt.Printf("Hello World\n") }
Example from Linguist:
// Autogenerated by Thrift Compiler (1.0.0-dev) // DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING package linguist import ( "bytes" "fmt" "git.apache.org/thrift.git/lib/go/thrift" ) // (needed to ensure safety because of naive import list construction.) var _ = thrift.ZERO var _ = fmt.Printf var _ = bytes.Equal func init() { }
Example from Wikipedia:
package main import ( "fmt" "time" ) func readword(ch chan string) { fmt.Println("Type a word, then hit Enter.") var word string fmt.Scanf("%s", &word) ch <- word } func timeout(t chan bool) { time.Sleep(5 * time.Second) t <- true } func main() { t := make(chan bool) go timeout(t) ch := make(chan string) go readword(ch) select { case word := <-ch: fmt.Println("Received", word) case <-t: fmt.Println("Timeout.") } }
break case chan const continue default defer else fallthrough for func go goto if import interface map package range return select struct switch type var

Language features

Feature Supported Token Example
Floats โœ“
// \d+(\.\d+[eE][+\-]?\d+|\.\d*|[eE][+\-]?\d+)
Hexadecimals โœ“
// 0[xX][0-9a-fA-F]+
Octals โœ“
// 0[0-7]+
Conditionals โœ“
Switch Statements โœ“
Constants โœ“
Case Sensitivity โœ“
Assignment โœ“ =
Print() Debugging โœ“ fmt.Println
Message Passing โœ“
Line Comments โœ“ //
// A comment
Variadic Functions โœ“
// This variadic function takes an arbitrary number of ints as arguments.
func sum(nums ...int) {
  fmt.Print("The sum of ", nums) // Also a variadic function.
  total := 0
  for _, num := range nums {
    total += num
  }
  fmt.Println(" is", total) // Also a variadic function.
}
Type Inference โœ“
Lists โœ“
myList := []int{1, 2, 3}
File Imports โœ“
import (
   "fmt"
   "math"
)
import . "fmt"
import _ "io"
import log "github.com/foo/bar"
import m "math"
Increment and decrement operators โœ“
i := 0
i++
i--
Integers โœ“
i, j := 42, 2701
Booleans โœ“
c := true
MultiLine Comments โœ“ /* */
/* A comment
*/
Comments โœ“
// A comment
Pointers โœ“
package main

import "fmt"

func main() {
  i, j := 42, 2701

  p := &i         // point to i
  fmt.Println(*p) // read i through the pointer
  *p = 21         // set i through the pointer
  fmt.Println(i)  // see the new value of i

  p = &j         // point to j
  *p = *p / 37   // divide j through the pointer
  fmt.Println(j) // see the new value of j
}
Strings โœ“ "
"hello world"
Case Insensitive Identifiers X
Semantic Indentation X
Operator Overloading X

View source

- Build the next great programming language ยท About ยท Acknowledgements ยท Published by Breck's Lab