Notepad/enter/Coding Tips (Classical)/Terminal Tips/2. CLI Tools/Languages/Middle/Go/Welcome to Go.md

2.4 KiB
Raw Permalink Blame History

Go Programming Language

For a great textbook to learn Go, read this textbook by Donovan & Kernighan

Additionally all the commands and additional settings for flags are found here. Why learn Go? Well, their entire webpage that explained literally that exact question may have had something to do with it. And I saw a youtube video yesterday saying how it was better than Rust, the literal most "loved" language currently in terms of long-term performance. So both of those two things got me sold.

They have a rather intuitive learning module called The Go Playground which makes it actually desirable to learn even.

// You can edit this code!
// Click here and start typing.
package main

import "fmt"

func main() {
	fmt.Println("Hello, 世界")
}

And tons more examples to try and out and learn from such as Conway's Game of Life and more.

This is how a fibonacci sequence could be implemented:


package main

import "fmt"

// fib returns a function that returns
// successive Fibonacci numbers.
func fib() func() int {
	a, b := 0, 1
	return func() int {
		a, b = b, a+b
		return a
	}
}

func main() {
	f := fib()
	// Function calls are evaluated left-to-right.
	fmt.Println(f(), f(), f(), f(), f())
}

With the output being: 1 1 2 3 5

When actually looking at it, it's kinda cool. It's not actually hard recursion like the way that it seemed like before with lisp.

Go Terms:

  • A Module
    • A module is a collection of Go packages stored in a file tree with a go.mod file at its root. The go.mod file defines the modulemodule path, which is also the import path used for the root directory, and its dependency requirements, which are the other modules needed for a successful build. Each dependency requirement is written as a module path and a specific semantic version.
    • To see examples of how to set up Go modules, visit here.
    • Another github example of using Go module conventions

Cool Repos: