Overview

Overview of Go Programming Language #

Last updated: September 22, 2024

About the Go Language #

Rather than being a nice language, Golang targets making the whole “long term software engineering experience” nicer.

Golang is simple to learn

  • Familiar C like syntax
  • Readable and relatively short language specification
  • UNIX like design across the language
Along with Rob Pike and Robert Griesemer the Turing award winning creator of UNIX is also a Go lang co-founder.

Golang includes only a small number of carefully selected features. In fact, Golang is remarkable for the features that it boldly leaves out of the language!

  • No exceptions and no assertions— instead, errors are explictly handled at the point they occur.

    f, err := os.Open("README.md")
    if err != nil {
      slog.Error("read", "error", err)
      os.Exit(1)
    }
    

    If a function can’t figure out how to locally handle a failure point, it returns the error as the last return value.

    if err != nil {
      return nil, error
    }
    
  • No inheritence— type composition using structs with embedded fields provide an alternative.

    type Animal struct {
      Name string
    }
    func (a Animal) Speak() { // Method on Animal struct
      fmt.Println(a.Name, "makes some sound")
    }
    
    type Dog struct {
      Animal
      Breed string
    }
    func (d Dog) Speak() {
      fmt.Println(d.Name, "barks")
    }
    
    dog := Dog{
      Animal: Animal{Name: "Lassie"},
      Breed: "Long-Haired Collie",
    }
    dog.Speak()
    

    And interfaces allow sharing behavior across types.

    interface Speaker {
      Speak()
    }
    
    func AnimalCouncil(animals []Speaker) {
        for _, animal := range animals {
            animal.Speak()
        }
    }
    
  • No type inference-— instead, types has to be explicitly cast.

    var i int = 10
    i = int(9.2)
    

    Using literals with the := operator is the only exception.

  • No operator overloading

  • No global functions— the top level scope in Golang is package level

  • No null typenil in Golang represents the absense of a value for pointer and interface types.

Golang core team is very careful in adding new features.

Before generics arrived in Go 1.18, many different approaches were proposed and rejected until a solution was found that fit well with the rest of the language.

Golang has CSP inspired concurrency built-in to the language with the go statement and the channel data type.

Golang has a strong source code compatibility gurantee— programs written for Go 1.0 will compile with any future Go compiler

Golang has Fast compile times and easy cross compilation — as easy as doing GOOS=linux GOARCH=arm64 go build . from any host OS to build for linux/arm64

Golang has a comprehensive standard library that takes a batteries included approach

  • For building server software, one can go a long way before needing to reach for third party libraries
  • For example, in Go 1.22 (Feb, 2024) net/http package’s router started supporting method matching and wildcards- making a web framework unncessary for some use cases.

Golang Timeline #

Incomplete
  • 2007 Inception during a long wait for a C++ build to complete at Google by Robert Griesemer, Rob Pike, and Ken Thompson
  • 2009 Nov Public announcement by the Go team consisting of Robert Griesemer, Rob Pike, Ken Thompson, Ian Taylor, Russ Cox, Jini Kim and Adam Langley. And intro video by Russ Cox.
  • 2012 Mar Go 1.0 Strong source compatiblity gurantee.
  • 2013 May Go 1.1 Method values.
  • 2015 Aug Go 1.5 Go compiler and runtime fully written in Go, concurrent garbage collector.
  • 2015 Oct The Go Programming Language book by Alan A. A. Donovan, Brian W. Kernighan published
  • 2017 Feb Go 1.8 HTTP/2 Push, http.Server.Shutdown, sort.Slice
  • 2021 Feb Go 1.16 Support for embedding file tress into application binary.
  • 2022 Mar Go 1.18 Generics, native fuzzing, module workspaces.
  • 2024 Feb Go 1.22 HTTP router enhancements.
  • 2022 Mar Go 1.18 Generics, native fuzzing, module workspaces.
  • 2023 Feb Go 1.20 Improved slice-to-array conversions.
  • 2024 Feb Go 1.22 HTTP router enhancements.

References #