Start with the Go Playground. Later, we'll talk about editors and editor tools.
You can write Go code here.
package main
import (
"fmt"
)
func main() {
fmt.Println("Hello, playground")
}
We will learn about package, import, func later. For now, let's look at the playground.
You can click on the share button to share code snippets, if you have questions and want to share some code, you can use this sharing URL. Someone else can troubleshoot it, get a different URL and share that back to you.
Some useful places to ask questions are: https://forum.golangbridge.org/. A lot of "heavy hitters" in the Go community hang out here.
In Go, we organize our code into packages. Go has a standard library, organized in packages. Here we're using package "fmt"
and the fmt.Prinln
function from that package. From package "fmt" I'm calling the Println
identifier.
That's a convention in Go, you have a package, some identifier; a variable, a constant, a function, that has been exported from that package. If you want to automatically import packages from the standard library, just check the Imports button, and when you click the format button, it will import automatically. It will also format you code in an idiomatic way.
When you hear someone say "idiomatic Go code," that is code written in the way that we in the Go community write Go.
Finally, click Run, and that will run your code. It compiles down to an executable, and execute it. Go compiles down to binary, a straight executable, doesn't run on top of another runtime or virtual machine. It's binary code on the hardware.
There's a mechanical sympathy that Go achieves. That's sympathy with the machine. Meaning Go will compile for the specific hardware it is running on, and compile in a way that it will run on that hardware in the most efficient way possible.