Перейти к содержимому

Andersen - 1

General questions to understand overall motivation and interest:

  • For which types do you need to allocate memory? Ways to allocate memory a) Required for types: slice, map, array, chan b) var i = 0 c) make creates an object with default values d) new creates a pointer to an object go/channels
  • How to implement an OOP approach in Go? Inheritance a) Encapsulation: private variables and methods are written in lowercase b) Inheritance: composition and method embedding c) Polymorphism: use of interfaces go/structs-methods
  • Interfaces. Purpose. Usage a) Polymorphism b) Type determination: type switch c) reflect package go/interfaces
  • Arrays, slices, strings. Internal structure. How they are passed (pointer or value) a) Arrays are immutable b) Slices are mutable; the append function go/slices-arrays
  • Memory allocation. Stack and heap a) Each goroutine allocates an expandable stack b) Pointers and the structures they point to escape to the heap c) Garbage collector: mark & sweep algorithm go/concurrency
  • Channels. Purpose. Types of channels a) What is a channel under the hood? Usage patterns i) Buffered - works asynchronously ii) Unbuffered iii) Passing values between goroutines b) What happens if you write to a closed channel? i) Panic c) What happens if you read from a closed channel? i) Default value d) Non-blocking write/read to a channel? i) select case ii) How to check if a channel is closed? iii) if v, ok:= <-channel; ok e) What does len(chan) of a unidirectional channel return? i) The number of elements in the channel go/concurrency
  • Generics. What are they? How do they work in Go? a) Go 1.18: syntax, purpose. How did you manage without them? go/generics
  • Garbage collection. Algorithms a) Tri-color algorithm (black, gray, white), mark & sweep go/memory-gc
  • Concurrency a) What are goroutines? How are they structured? How many goroutines can there be? Ratio of goroutines to the number of processors i) A goroutine is a function executed in parallel with others ii) Created via go + function call iii) Lightweight (~2 KB of memory) iv) Preemptive multitasking b) The runtime package i) Documentation: pkg.go.dev/runtime ii) runtime.NumGoroutine() - returns the number of goroutines iii) StartTrace() and StopTrace() - execution tracing c) Communication between goroutines i) Using context.Context for lifecycle management d) Ways to control goroutine execution (WaitGroup, ErrorGroup) i) sync.WaitGroup - waiting for a group of goroutines to finish go/concurrency
  • Context. Types. Purpose a) context.Background(), context.TODO() b) WithDeadline() - termination by time c) WithTimeout() - termination after an interval d) Data storage: key-value e) Cancellation via cancel() go/context
  • Goroutine leaks. How to avoid them? a) Goroutines run independently of main b) Infinite loops without exit conditions c) Explicit termination via channels or context d) Using sync.WaitGroup go/concurrency
  • Allocations and sync.Pool a) Memory allocation for structures and global variables b) Deleting from a map/slice does not free memory c) Reusing variables and sync.Pool go/sync
  • Data race & race condition a) What is a data race? i) Competition for data access b) Ways to prevent it i) Mutexes (sync.Mutex, sync.RWMutex ), channels c) What are mutexes? i) RWMutex - separating reads (RLock() ) and writes (Lock() ) d) Mutexes in the OS i) Protect memory regions from simultaneous access go/channels
  • Profiling. Differences between profiling on desktop and server a) pprof - a performance analysis tool go/perf-profiling
  • Sorting algorithms? Practice. What algorithm does the sort function use? How does quicksort work? algorithms/sorting-search
  • Task: Sort a string alphabetically. If the letter is a vowel, the uppercase letter is greater; if it is a consonant, it is smaller go/strings-runes
  • Task: Write a program that prints numbers from 1 to 100. For multiples of 3, print «Fizz» instead; for multiples of 5, print «Buzz»; for multiples of both 3 and 5, print «FizzBuzz» go/basics
  • Task: F+1=? algorithms/general
  • What types of databases do you know? a) Relational (SQL) b) Key-value (Redis) c) Columnar (Cassandra) d) Indexes e) In-memory (Memcached) sql/general
  • PostgreSQL. Types of indexes. Isolation levels sql/indexes
  • Database scaling methods sql/replication-scaling
  • Task: There is a marketplace like AliExpress. Determine the seller whose total purchase amount from you is in second place. Build the table sql/general
  • Which ones exist? What are they used for? go/basics