Interviews are always a stress both for an employer and an applicant. Therefore, the only wise decision would be to prepare for the meeting with the applicant in advance. Especially given the fact that questions asked for various seniority levels should be different.
Whether you're preparing to hold a Go interview or just want to present yourself as a cutting edge developer, this list is the right choice for you. Today we'll help you gather the list of interesting questions (10 per every seniority level) to ask your future devs.
These questions and answers would be useful for both parts of the interview.
01
Go is an open source programming language developed by Google. It is also known as Golang. This language is primarily intended for systems programming.
02
Since Go is an open source programming language, it is very easy to create simple, reliable, and efficient software.
03
The Go programming language was developed by Robert Griesemer, Rob Pike, and Ken Thompson. It was developed by Google Inc. in 2009.
04
Go programs are made up of packages. The program runs in the main package. This program uses packages with import paths "fmt" and "math / rand".
05
The Go programming language does support universal programming.
06
Yes! Go is a case sensitive programming language.
07
String literals specify a string constant obtained by concatenating a sequence of characters.
There are two types of string literals:
08
The workspace contains Go code. The workspace is a directory hierarchy with three directories at the root.
09
The GOPATH environment variable specifies the location of the work area. You must set this environment variable when developing your Go code.
10
type Orange struct { Quantity int }
func (o *Orange) Increase(n int) { o.Quantity += n }
func (o *Orange) Decrease(n int) { o.Quantity -= n }
func (o *Orange) String() string { return fmt.Sprintf("%v", o.Quantity) }
func main() { var orange Orange orange.Increase(10) orange.Decrease(5) fmt.Println(orange) }
This is a tricky question because you might think it has something to do with setting the Quantity member variable incorrectly, but it will actually be set to 5 as expected. The real problem here, which is easy to overlook, is that the String() method that implements the fmt.Stringer() interface will not be called when the orange object is printed using the fmt.Println() function, because the String() is not defined for a value, but only for a pointer:
var orange Orange orange.Increase(10) orange.Decrease(5) fmt.Println(orange)
// Output: {5}
orange := &Orange{} orange.Increase(10) orange.Decrease(5) fmt.Println(orange)
// Output: 5
This is a delicate question, but the fix is easy. You need to override the String() method for a value instead of a pointer, in which case it will work for both pointers and values:
func (o Orange) String() string { return fmt.Sprintf("%v", o.Quantity) }
01
Go programming language advantages / benefits:
02
List of built-in Go support:
03
A goroutine is a function that usually runs concurrently with other functions. If you want to stop the goroutine, you pass the signal channel to the goroutine, which sends a value when you want the goroutine to stop.
The goroutine regularly polls this channel as soon as it detects a signal and exits.
Quit : = make (chan bool)
go func ( ) {
for {
select {
case <- quit:
return
default
// do other stuff
}
}
}()
// Do stuff
// Quit goroutine
Quit <- true
04
To write multiple strings in Go, you must use a raw string literal where the string is separated by back quotes.
05
The break statement is used to terminate a for loop or switch statement and transfer execution to the statement immediately following the for loop or switch.
06
The continue statement allows the loop to loop through the rest of its body and immediately re-check its condition before repeating.
07
The goto statement is used to transfer control to the tagged statement.
08
The syntax for a for loop in the Go programming language is:
for [condition | ( init; condition; increment ) | Range]
{
statement(s);
}
09
The syntax for creating a function in Go is:
func function_name( [parameter list] ) [return_types]
{
body of the function
}
10
A variable declaration of a static type is used to ensure that the compiler has one variable with a given type and name, so that the compiler does not need to know all the details about the variable for further processing. The variable declaration is only meaningful at compile time, the compiler needs the actual variable declaration at the time of linking the program.
01
The two values are swapped so simply:
a, b = b, a
To swap three values, we have to write:
a, b, c = b, c, a
Go's swap operation is guaranteed against side effects. The assigned values are guaranteed to be stored in temporary variables before the actual assignment begins, so the order of assignment does not matter. The result of the following operation: a: = 1; b: = 2; a, b, a = b, a, b are still equal to a = 2 and b = 1, without the risk of changing the value of a to the new reassigned value. It is useful to rely on this in many implementations of the algorithms.
For example, a function that swaps a slice of integers:
func reverse(s []int) {
for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 {
s[i], s[j] = s[j], s[i]
}
}
func main() {
a := []int{1, 2, 3}
reverse(a)
fmt.Println(a)
// Output: [3 2 1]
}
02
You copy the snippet using the built-in copy () function:
a := []int{1, 2}; b := []int{3, 4}; check := a; copy(a, b); fmt.Println(a, b, check)
// Output: [3 4] [3 4] [3 4]
Here, a check variable is used to store a reference to the original slice description to ensure that it was indeed copied.
In the following example, on the other hand, the operation does not copy the contents of the slice, but only its description:
a := []int{1, 2}; b := []int{3, 4}; check := a; a = b; fmt.Println(a, b, check)
// Output: [3 4] [3 4] [1 2]
You copy the map by navigating through its keys. Yes, unfortunately, this is the easiest way to copy a map in Go:
a := map[string]bool{"A": true, "B": true}; b := make(map[string]bool)
for key, value := range a { b[key] = value }
In the following example, only the map description is copied:
a := map[string]bool{"A": true, "B": true}; b := map[string]bool{"C": true, "D": true}; check := a
a = b; fmt.Println(a, b, check)
// Output: map[C:true D:true] map[C:true D:true] map[A:true B:true]
Go doesn't have a built-in facility for copying an interface. No, the reflect.DeepCopy() function does not exist.
03
You can compare the two structures using the == operator, as with other simple types. Just make sure they don't contain slices, maps, or functions, in which case the code won't compile.
type Foo struct { A int
B string
C interface{} }
a := Foo{A: 1, B: "one", C: "two"}
b := Foo{A: 1, B: "one", C: "two"}
println(a == b)
// Output: true
type Bar struct { A []int }
a := Bar{A: []int{1}}; b := Bar{A: []int{1}}
println(a == b)
// Output: invalid operation: a == b (struct containing []int cannot be compared)
You can compare two interfaces using the == operator if the underlying types are "simple" and identical. Otherwise, the code will panic at runtime:
var a interface{}; var b interface{}
a = 10; b = 10
println(a == b)
// Output: true
a = []int{1}; b = []int{2}
println(a == b)
// Output: panic: runtime error: comparing uncomparable type []int
Both structures and interfaces that contain maps, slices (but not functions) can be compared to the reflect.DeepEqual() function:
var a interface{}; var b interface{}
a = []int{1}; b = []int{1}
println(reflect.DeepEqual(a, b))
// Output: true
a = map[string]string{"A": "B"}
b = map[string]string{"A": "B"}
println(reflect.DeepEqual(a, b))
// Output: true
temp := func() {}; a = temp; b = temp
println(reflect.DeepEqual(a, b))
// Output: false
The bytes package has useful helper functions for comparing byte slices: bytes.Equal(), bytes.Compare(), and bytes.EqualFold(). The latter is for case-insensitive text string comparisons, which are much faster than reflection.DeepEqual().
04
The syntax of the GO programming language is specified using the Extended Backus-Naur Form (EBNF):
05
In Go, interfaces are a way to define the behavior of an object. An interface is created using the word "type" followed by the name and the keyword interface. An interface is defined as two things.
06
A type assertion takes the value of an interface and retrieves the value of the specified explicit type from it.
Type conversion is used to convert dissimilar types in Golang.
07
In the Go programming language, there are several different types of functions called methods. In the method declaration syntax, "getter" is used to represent the container of the function. This receiver can be used to call a function using "." operator.
08
The Go programming language has a special type of switch for checking the type of a variable at runtime. This switch is called a switch type.
09
Global variables are not recommended because they can be accessed by multiple goroutines (threads) at the same time, and this can easily lead to unexpected behavior causing arbitrary results.
10
Modular programming is a way to divide a program into subroutines (modules / functions) for maximum efficiency.
Defining more general functions makes it easier to reuse functions, such as built-in library functions.
There are hundreds of battle-proven software development experts in our Talent Network.
Are you a Go/Golang developer looking for amazing projects? Join as a Talent