Common Interview Questions for Golang developers.
Thanks to the simplicity of Golang and soaring interest in using Golang as the programming language to develop new software. Many employers are looking to hire Golang developers even though Golang is still consider a young programming language.
Here are some of the Golang specific technical questions and answers that both interviewer and interviewee can use to prepare for a job interview.
1. Give a summary of Golang.
A system programming language developed at Google. It has inbuilt garbage collection and supports concurrency. The code can be compiled into a single executable binary and don't need addition library or runtime to execute it on server.
2. Can you declare a class in Golang?
Yes, Golang has a unique way of implementing class with the type interface.
See here on how to declare class in Golang
3. Does Go supports generic? ( trick question )
No (as of 2015)
4. What are the commands available in Golang to import codes from repositories such as GitHub or BitBucket?
go get
and go install
commands
5. A buffer was created with make()
function and Go allocated some memory for the buffer. How do you destroy the buffer to reclaim back the memory?
buffer = nil
During runtime, buffer = nil will cause it to be garbage collected.
6. What are these ? (trick question)
var num int ( integer variable)
var ptr *int (a pointer)
num = 10 (assign value of 10 to variable num)
ptr = &num (pointer holding the memory address of variable num)
7. What are the notable differences between a slice and array ?
Array size is fixed, slice size is not. Can dynamically increase or decrease a slice's size during runtime but not for array. Slice is similar to a linked list, can do push, pop, FIFO, LIFO on slice. Use builtin append, copy functions to manipulate slice.
8. What's the difference between cap()
and len()
?
Len()
- gives the number of elements inside a slice.
Cap()
- gives the capacity of the slice. Number of elements the slice can accommodate.
9. Hash table or hash map allows fast lookup. How does Go implements hash map? (trick question)
The equivalent of hash table in Golang is map
.
hash-table := make(map[string]string)
10. Which of the following functions, variables or identifiers that are exportable or can be invoked from another function externally and why? (trick question)
var aName // private, only available within the function or declared scope
var BigBro // public (exportable)
var 123abc // illegal
var 爱 = "love" // public (exportable)
func (p *Person) SetEmail(email string) { // public because SetEmail() function starts with upper case
p.email = email
}
func (p Person) email() string { // private because email() function starts with lower case
return p.email
}
See here to know more about public and private identifiers
Summary :
In reality, even senior Golang developers can be trapped by some of the questions asked during interview. Most people can code comfortably in with the help of search engines such as Google or DuckDuckGo. As long as the potential candidate knows how to answer basic Golang questions and able to find answers on online forums to get the job done in time, it is good enough.
Tip :
As of 2015, it is easy to spot a cheat if you see any developer resume stating that he or she has 10 years++ experience in Golang. ;-)
References :
https://golang.org/ref/spec#identifier
https://www.socketloop.com/tutorials/golang-of-hash-table-and-hash-map
See also : Guide to identify the types of software developers
By AdamNg
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Something interesting
Advertisement
Tutorials
+7.2k Golang : Convert source code to assembly language
+12.1k Golang : 2 dimensional array example
+12.2k Golang : Extract part of string with regular expression
+11.9k Linux : How to install driver for 600Mbps Dual Band Wifi USB Adapter
+11.7k Golang : Determine if time variables have same calendar day
+6.5k Golang : Check if password length meet the requirement
+9.2k Golang : Terminate-stay-resident or daemonize your program?
+7.3k Golang : Handling Yes No Quit query input
+17.2k Golang : Check if IP address is version 4 or 6
+4.6k Which content-type(MIME type) to use for JSON data
+26.4k Golang : Encrypt and decrypt data with AES crypto
+16.6k Golang : read gzipped http response