- Go is
faster
than the interpreted languages like Python, JavaScript, Php. - Go has a
fast compilation
speed than Rust, C++, Java. - It doesn't have the same
execution speed
as other languges.
go run main.go
go run main.go -package=channels
make run -package=channels
go mod init <module-name>
go run main.go
go build && ./<module-name>
go install
Build and install locally in admin folder.
- main.go will not be understood by the computer.
- During the compilation we create an executable program.
Distributing
programs that are natively compiled is much easier.- If we distribute python code, then the other person needs to have python
installed
.
- Go is both
statically
typed andstrongly
typed language. - Go enforces static typing meaning variable types are
known
before the code runs. - Strongly typed meaning the variable types are
fixed
and cannot be changed.
- Go has garbage collection, which allows to
clean up
resources. - However, it does not have
JVM
like Java, allowing minimal memory usage. - A small code is added known as
Go Runtime
, which handles memory management.
defer
keyword is used to close a resource.- The parameters will be checked but the function will be called before the current function
returns
.
- Keep interfaces
small
. - Interfaces should have
no knowledge
about satisfying types. (Ex: isFireTruck()) - Interfaces are not
classess
.
- Go has
errors
package, which allows to create custom errors. - We should avoid using
panic
andrecover
keywords. - Alternative to that is the
Log.Fatal()
method.
- The main reason should be to
change values
in function calls. - Pointers are
dangerous
and can lead to bug.
- The packages beside main, are library packages
exporting
some function. - Hide
internal
logic. - Don't change APIS.
- Don't
export functions
from the main package. - Package should have no information about their
dependents
.
- A
repository
contains one or more modules. - A module is a
collection
of Go packages that are released together.
- A send/receive to nil channel (create without make)
blocks
forever. - A send to close channel
panicks
. - A receive from closed channel return the
zero value
immediately.