- Go is
fasterthan the interpreted languages like Python, JavaScript, Php. - Go has a
fast compilationspeed than Rust, C++, Java. - It doesn't have the same
execution speedas 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 installBuild and install locally in admin folder.
- main.go will not be understood by the computer.
- During the compilation we create an executable program.
Distributingprograms that are natively compiled is much easier.- If we distribute python code, then the other person needs to have python
installed.
- Go is both
staticallytyped andstronglytyped language. - Go enforces static typing meaning variable types are
knownbefore the code runs. - Strongly typed meaning the variable types are
fixedand cannot be changed.
- Go has garbage collection, which allows to
clean upresources. - However, it does not have
JVMlike Java, allowing minimal memory usage. - A small code is added known as
Go Runtime, which handles memory management.
deferkeyword 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 knowledgeabout satisfying types. (Ex: isFireTruck()) - Interfaces are not
classess.
- Go has
errorspackage, which allows to create custom errors. - We should avoid using
panicandrecoverkeywords. - Alternative to that is the
Log.Fatal()method.
- The main reason should be to
change valuesin function calls. - Pointers are
dangerousand can lead to bug.
- The packages beside main, are library packages
exportingsome function. - Hide
internallogic. - Don't change APIS.
- Don't
export functionsfrom the main package. - Package should have no information about their
dependents.
- A
repositorycontains one or more modules. - A module is a
collectionof Go packages that are released together.
- A send/receive to nil channel (create without make)
blocksforever. - A send to close channel
panicks. - A receive from closed channel return the
zero valueimmediately.
- make() - Provides a way to make maps, slices and channels with predefined size and capacity.
- len() - Returns the length of the array, slice, map and channel.
- append() - Appends a slice of type T to another slice.
godoccommand is used to generate a proper documenting.- Not deep dived into the details.