Exercises based on https://www.udemy.com/share/1013gwCUcSdVxRRnQ=/
Best way to check the code is to run in debug mode, stepping into functions and examining variables and program execution flow.
- each section is encapsulated in a separate
go
file - each file has one meted exposed that in turn calls all other methods
- method names describe type of exercise, sometimes comments are used for clarity
- use VS Code debugger to step through code
- set breakpoint on the module you want to check out: F9
- run with debugger: F5
- from here you can:
- step into a function: F11
- step over line of code (let it execute): F10
- step out from function (useful for stepping out of go code and long loops): Shift + F11
Learning topics with random notes and observations.
-
-
Go has type inference and compiler was able to infer type of all variables so far
-
:= operator creates a variable and assigns value to it in one statement
-
",ok" or comma ok idiom:
if seconds, ok := timeZone[tz]; ok { return seconds }
-
-
- functions that have receiver (operate on a type), are called methods and usually mutate state
- functions that are not methods try to be "pure functions"
-
there is no enforcement of pure functions concept in Go
- interfaces allow to define behavior and polymorphism like in C#
- not sure if it's idiomatic, but it's possible to use functional composition in Go, like in F#. Looks like this is under callback pattern.
-
- & operator shows variable address
- * returns a value stored at an address
- * with a type like *int is a type of pointer
- * with a value like *valueName is a de-referencing operator to show what value is under a memory address
- use pointers with large data sets, instead of passing it by value (similar as passing by reference in C#?)
-
Application
-
Concurrency
-
Channels
-
Error handling
-
Writing documentation
-
Testing & benchmarking