Go

Go is currently my favorite programming language.

I mostly love the tooling around it like VS Code and its Go plugin. The powerful go command line tool and the rich ecosystem of libraries and tools that people have built.

Go promotes composition over inheritance.

Commenting Go code

  • Comments documenting declarations should be full sentences.
  • Comments should begin with the name of the thing being described and end in a period.

Error checking

  • You can log.Fatal(err) when playing with code.
    • In actual applications you need to decide what you need to do with each error response - bail immediately, pass it to the caller, show it to the user, log it and continue, etc ...

Notes

  • I can call functions from anywhere if they are in the same package.
  • The package “main” tells the Go compiler that the package should compile as an executable program instead of a shared library.
  • Note that any type implements the empty interface interface{} because it doesn't have any methods and all types have zero methods by default.
  • Simply pushing my source code to GitHub, makes it go gettable.
  • Interface types represent fixed sets of methods.
  • the prevailing wisdom in Go is to use a flat directory structure and only create new directories when you are building self-contained functionality.
  • go get = download the source code to your PC.
  • go install = download, build, and put it in the path so you can use it.
  • I don't need to comment all functions as some are self describing. I do need to comment exported functions however.
  • What works well is to use Go to create an HTTP API and leave the rest (html templates etc) to a client-side frontend (e.g. React). That gives you the best of both worlds: a fast and lightweight backend in Go with a rich frontend in JS.
  • This is a core concept in Go’s type system; instead of designing our abstractions in terms of what kind of data our types can hold, we design our abstractions in terms of what actions our types can execute.

results matching ""

    No results matching ""