Notepad/enter/Coding Tips (Classical)/Terminal Tips/Languages/Go/Welcome to Go.md

61 lines
2.3 KiB
Markdown
Raw Blame History

This file contains invisible Unicode characters!

This file contains invisible Unicode characters that may be processed differently from what appears below. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to reveal hidden characters.

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

# Go Programming Language
For a great textbook to learn Go, read [this textbook by Donovan & Kernighan](https://drive.google.com/file/d/1-n9s6Qc0JYdQHz86GbUTaJ_j3Fzp7IE7/view?usp=sharing)
Additionally all the commands and additional settings for flags [are found here. ](https://pkg.go.dev/cmd/go)
Why learn Go? Well, their entire [webpage](https://go.dev/solutions/#case-studies) 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 ](https://go.dev/play/)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](https://go.dev/play/) 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](https://go.dev/ref/spec#Packages) stored in a file tree with a `go.mod` file at its root. The `go.mod` file defines the modules _module 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](http://semver.org/).
- To see examples of how to set up Go modules, visit [here](https://go.dev/blog/using-go-modules).
- Another github example of using[ Go module conventions](https://github.com/amitsaha/using-go-modules)