Compare GO to other AWS scripting languages:
Property | Node.js | Python | Go |
---|---|---|---|
Scripting Language | yes | yes | no |
Files / Program | many | many | one |
Typing | dynamic | dynamic | static |
Multi-OS | yes | limited | yes |
Node.JS an Python are interpreted languages, that means the source code is interpreted at runtime. This means a little bit more flexibility like ducktyping
, but usually that means a slower execution. Also you have to have the interpreted itself installed to run a program.
GO compiles programs statically. That means a standalone single executable is created. And since GO 1.16 you can embed files into you binary.
This binary will be compiled for a target OS (Operation System). If you use go programs locally on you machine, then this is the target OS. But you can create running binaries for other OSs on your machine also.
This compilation is so fast, that you also can directly run a go programs.
package main
import "fmt"
func main() {
fmt.Println("go")
}
go run main.go
Line | Meaning |
---|---|
package main |
This is the main/root package |
import "fmt" |
import the library “fmt” = format |
func main(){} |
the main function gets executed |
fmt.Println("go") |
Use the function “Println” = print with new line from the “fmt” library |
go run main.go
go run
will directly run go files.
An output will look like
go run main.go
go
Go has done the compilation and the execution steps.
We can also split the compilation and the execution.
dist
for distribution:mkdir dist
go build -o dist/printer main.go
go build
just compiles a file. Now we have the standalone executable printer
in the dist
directory.
Let`s run it:
dist/printer
go
You see that this is real fast.
See the full source on github.