Level: IntermediateInterview

Go Difference Between Questions: Quick Revision (Part 28)

Updated 9 min read
Go Difference Between Questions featured image: array vs slice, new vs make and Mutex vs channel cards

These Go difference between questions put two similar ideas side by side and ask you to explain the gap. They cover types, collections, methods, interfaces, errors, packages, concurrency and backend tools. We gathered them from public interview lists and coding rounds, then rewrote each one in plain words.

This post is questions only, so answer each one in your own words first. When you need help, read Go slices and arrays, Go value vs pointer receivers and Go WaitGroup and Mutex. Also, finish Part 27 on tricky output first, because many of those traps come from these pairs.

How to Use These Go Difference Between Questions

Answer each of these Go difference between questions with one line for each side, then one line on when to pick which. That simple shape keeps your answer short and clear. Finally, try the scenario questions, since they ask you to choose under real limits.

The table below lists each section and its number of questions.

SectionWhat it testsQuestions
Basics and typesvar, :=, const and type rules16
Collections and stringsArray, slice, map and string15
Functions and interfacesMethods, receivers and interfaces15
Errors and packagesErrors, panics and modules14
ConcurrencyGoroutines, channels and locks16
Backend and toolsHTTP, data, testing and deploy15
Go Difference Between Questions diagram showing six areas of pairs that interviewers compare
The six areas of pairs that interviewers like to compare.

Go Difference Between Questions on Basics and Types

Before you answer, study Go variables, constants and data types. These Go difference between questions start with the syntax every Go file uses.

  1. What is the difference between var x int and x := 0?
  2. How does a constant differ from a variable that never changes?
  3. Compare a typed constant with an untyped constant.
  4. When would you pick int over int64, and why?
  5. How does a type definition such as type Celsius float64 differ from an alias such as type C = float64?
  6. Compare a byte with a rune, then say when you need each.
  7. What separates a conversion such as float64(x) from a type assertion such as x.(float64)?
  8. How do break and continue differ inside a loop?
  9. Explain the gap between switch with fallthrough and a normal switch case.
  10. What is the difference between a package level variable and a local variable?
  11. How does the zero value of a pointer differ from the zero value of a struct?
  12. Compare go run with go build, for example in CI.
  13. What separates an exported name from an unexported name?
  14. How does shadowing a variable differ from assigning to it?
  15. Scenario: when a team argues about var versus := style, which rule of thumb would you suggest?
  16. Scenario: when a refactor turns a type definition into an alias, what could break?

Go Difference Between Questions on Collections and Strings

Before you answer, study Go slices and arrays and Go maps. Collections hide most of the surprises, so these Go difference between questions look at copies and capacity.

  1. What is the difference between an array and a slice?
  2. How does length differ from capacity in a slice?
  3. Compare a nil slice with an empty slice, especially in JSON output.
  4. What separates new from make?
  5. How does copy differ from append when you duplicate a slice?
  6. Explain the gap between a map with a missing key and a key that holds the zero value.
  7. When would you pick a map over a slice of structs?
  8. Compare a string with a []byte, since one of them is read-only.
  9. What is the difference between len(s) and utf8.RuneCountInString(s)?
  10. How do strings.Builder and bytes.Buffer differ?
  11. Compare sort.Slice with slices.Sort, then pick one for new code.
  12. What separates a map of values from a map of pointers?
  13. How does range over a slice differ from range over a map in order?
  14. Scenario: when a slice of a big file buffer keeps memory alive, would you slice or copy, and why?
  15. Scenario: when a lookup over 10,000 items is slow, would you choose a map or a sorted slice, and why?

Go Difference Between Questions on Functions and Interfaces

Before you answer, study Go value vs pointer receivers and Go interfaces. These Go difference between questions test how behaviour attaches to types.

  1. What is the difference between a function and a method?
  2. Compare a value receiver with a pointer receiver.
  3. How does a method value differ from a method expression?
  4. What separates an interface from a struct?
  5. How does any differ from a type parameter constrained by any?
  6. Compare a type assertion with a type switch.
  7. Explain the gap between a nil interface and an interface holding a nil pointer.
  8. When would you pick an interface over a function type?
  9. What is the difference between embedding a struct and holding it in a named field?
  10. How do generics differ from interfaces for reuse?
  11. Compare a closure with a plain function, for example in a counter.
  12. What separates defer from a direct call at the end of a function?
  13. How does a variadic parameter differ from a slice parameter?
  14. Scenario: when a type has some value and some pointer methods, which change would you make, and why?
  15. Scenario: when a helper takes any and uses many type assertions, would generics or interfaces fit better?

Go Difference Between Questions on Errors and Packages

Before you answer, study Go error handling and Go modules and packages. These Go difference between questions compare tools for failure and for code layout.

  1. What is the difference between an error and a panic?
  2. Compare errors.New with fmt.Errorf, so that you know when to wrap.
  3. How does %w differ from %v inside fmt.Errorf?
  4. What separates errors.Is from errors.As?
  5. Explain the gap between a sentinel error and a custom error type.
  6. How does log.Fatal differ from panic?
  7. Compare recover with handling an error value.
  8. What is the difference between a package and a module?
  9. How does go.mod differ from go.sum?
  10. Compare go get with go install, since both download code.
  11. What separates an internal package from a normal one?
  12. How do init functions differ from main?
  13. Scenario: when a library calls log.Fatal on bad input, what would you change and why?
  14. Scenario: when a caller needs the HTTP status from an error, would you pick a sentinel or a custom type?

Go Difference Between Questions on Concurrency

Before you answer, study Go channels and Go WaitGroup and Mutex. Concurrency pairs come up in every backend interview, so these Go difference between questions matter a lot.

  1. What is the difference between concurrency and parallelism?
  2. Compare a goroutine with an OS thread, for example in stack size.
  3. How does a buffered channel differ from an unbuffered one?
  4. What separates a Mutex from an RWMutex?
  5. When would you pick a channel over a Mutex?
  6. Explain the gap between a WaitGroup and errgroup.
  7. How does sync/atomic differ from a Mutex for a counter?
  8. Compare a data race with a race condition.
  9. What is the difference between closing a channel and setting it to nil?
  10. How does select with default differ from select without default?
  11. Compare context.WithCancel with context.WithTimeout.
  12. What separates time.After from time.NewTimer?
  13. How does sync.Map differ from a map guarded by a Mutex?
  14. Compare a worker pool with one goroutine per task.
  15. Scenario: when shared state is a single counter, would you choose a channel, a Mutex or an atomic, and why?
  16. Scenario: when a team wraps every map in sync.Map, what would you suggest instead?

Backend and Tooling Pairs

Before you answer, study Go REST API tutorial and Go gRPC tutorial. These Go difference between questions close with the tools you use on the job.

  1. What is the difference between REST and gRPC?
  2. Compare PUT with PATCH, especially for partial updates.
  3. How does http.Handler differ from http.HandlerFunc?
  4. What separates database/sql from pgx?
  5. When would you pick sqlc over an ORM such as GORM?
  6. Explain the gap between offset and cursor pagination.
  7. How does a unit test differ from an integration test?
  8. Compare a fake with a mock, then say which one you reach for first.
  9. What is the difference between a benchmark and a profile?
  10. How does a liveness probe differ from a readiness probe?
  11. Compare a session cookie with a JWT.
  12. What separates bcrypt from SHA-256 for passwords?
  13. How does a single-stage Docker build differ from a multi-stage one?
  14. Scenario: when a mobile app and ten internal services share one backend, which API styles would you pick for each?
  15. Scenario: when tests take too long, which tests would you keep as unit tests and which as integration tests?

Code Reading Questions

Read each program carefully and predict the output before you run it. Then explain the result in your own words.

package main

import "fmt"

func setArr(a [3]int)  { a[0] = 100 }
func setSlice(s []int) { s[0] = 100 }
func grow(s []int)     { s = append(s, 4); s[0] = -1 }

func main() {
    arr := [3]int{1, 2, 3}
    sl := []int{1, 2, 3}
    setArr(arr)
    setSlice(sl)
    fmt.Println(arr, sl)
    grow(sl)
    fmt.Println(sl, len(sl))
}
  1. What does the first line print, and how does it show the gap between arrays and slices?
  2. Why does grow change neither the first element nor the length of sl?

The second program compares new, make and nil values.

package main

import "fmt"

func main() {
    p := new([]int)
    s := make([]int, 2)
    fmt.Println(*p == nil, len(*p), s, len(s))

    var m map[string]int
    fmt.Println(m["a"], len(m))
    m2 := make(map[string]int)
    m2["a"]++
    fmt.Println(m2)

    var ch chan int
    bc := make(chan int, 1)
    bc <- 7
    fmt.Println(ch == nil, len(bc), cap(bc))
}
  1. What does each line print, and why is *p a nil slice while s is not?
  2. Why can you read from the nil map m but not write to it?

Quick Revision Table for Common Pairs

Use the table below as a final check before your interview. It sums up the pairs that come up most often.

PairFirst oneSecond one
Array vs sliceFixed size, copiedGrows, shares an array
new vs makeAny type, returns *TSlice, map, chan, returns T
Value vs pointer receiverWorks on a copyChanges the original
error vs panicNormal failureBug or broken state
Buffered vs unbufferedWaits only when fullWaits for a receiver
Mutex vs channelGuards shared dataPasses ownership of data

Also, many interviewers ask about new and make in detail. The diagram below shows the difference side by side.

Go difference between diagram comparing new with make
new returns a pointer to a zero value of any type, while make builds a ready slice, map or channel.

Official Resources

These official pages explain the rules behind these questions.

Quick Recap

  • These Go difference between questions cover basics, collections, functions, errors, concurrency and backend tools.
  • Arrays copy, while slices share a backing array.
  • new returns a pointer, while make builds slices, maps and channels.
  • A pointer receiver changes the value, while a value receiver works on a copy.
  • Errors are normal results, while panics signal bugs.
  • Use channels to pass ownership and a Mutex to guard shared data.

What’s Next?

By now, you have Go difference between questions for every common pair. Study the answers in your own notes, then check them against the Go interview topics study guide.

Next up: Senior Go developer interview questions (Part 29)