0
0
Goprogramming~20 mins

Why Go is widely used - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
๐ŸŽ–๏ธ
Go Concurrency Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
๐Ÿง  Conceptual
intermediate
2:00remaining
Why is Go popular for concurrent programming?

Go has built-in support for concurrency. Which feature makes it easy to write programs that do many things at once?

AUsing global variables for synchronization
BManual thread management like in C or Java
COnly single-threaded execution is supported
DGoroutines that are lightweight threads managed by Go runtime
Attempts:
2 left
๐Ÿ’ก Hint

Think about what Go provides to run multiple tasks without heavy system threads.

โ“ Predict Output
intermediate
2:00remaining
Output of Go code using goroutines and channels

What is the output of this Go program?

Go
package main
import (
  "fmt"
  "time"
)
func main() {
  ch := make(chan string)
  go func() {
    time.Sleep(100 * time.Millisecond)
    ch <- "Hello"
  }()
  msg := <-ch
  fmt.Println(msg)
}
AHello
BCompilation error
CNo output
DDeadlock error
Attempts:
2 left
๐Ÿ’ก Hint

Consider how channels synchronize goroutines.

โ“ Predict Output
advanced
2:00remaining
What does this Go code print?

Consider this Go code snippet. What will it print?

Go
package main
import "fmt"
func main() {
  m := map[string]int{"a": 1, "b": 2}
  for k, v := range m {
    if k == "a" {
      m["c"] = 3
    }
    fmt.Println(k, v)
  }
}
ARuntime panic: concurrent map iteration and map write
B
a 1
b 2
CCompilation error
D
a 1
b 2
c 3
Attempts:
2 left
๐Ÿ’ก Hint

Think about modifying a map while iterating over it.

๐Ÿง  Conceptual
advanced
2:00remaining
Why is Go's simplicity a key advantage?

Go is designed to be simple and easy to read. Which of these is NOT a reason why this simplicity helps developers?

AIt reduces the chance of bugs by avoiding complex features
BIt forces developers to write verbose and complicated code
CIt makes code reviews and maintenance easier
DIt helps teams onboard new members faster
Attempts:
2 left
๐Ÿ’ก Hint

Think about how simplicity affects code clarity and teamwork.

๐Ÿš€ Application
expert
2:00remaining
Identify the output of this Go concurrency pattern

What will this Go program print?

Go
package main
import (
  "fmt"
  "sync"
)
func main() {
  var wg sync.WaitGroup
  for i := 0; i < 3; i++ {
    wg.Add(1)
    go func(i int) {
      defer wg.Done()
      fmt.Print(i)
    }(i)
  }
  wg.Wait()
}
A012
B210
C012 or 021 or 102 or 120 or 201 or 210 (any order of 0,1,2)
DCompilation error
Attempts:
2 left
๐Ÿ’ก Hint

Think about how goroutines run concurrently and print order.