GoTheBiggerPicture Flashcards
Main problems solved by Go-Lang
- In-efficient Compilation
- In-efficient Execution
- Complex programming model
From Which language syntax is inspired in Go lang?
‘C Language’
Is Go procedural or Object Oriented ?
It is both.
Is Go Garbage collected ?
Yes Go language automatically performs garbage collection.
what it means when we say Go is fully compiled language?
It means, the Go compiled code doesn’t requires a “mediator” runtime to execute the same. It can be directly executable by the OS.
Unlike other languages like Java or Python, which requires a “mediator” runtime to execute the compiled code, the Go doesn’t requires any runtime same.
Does Go provides Single Binary output after compilation ?
yes, to make deployment easier, the Go compiler provides single binary output for deployment.
When first version of Go was released and what’s its release cycle ?
First Version: 2012 - 1.0
Release Cycle: Every six Month
Current Version: 1.20
What are the go inbuilt packages which provide network supports?
net and net/http
Which package in Go language provides “concurrency” support ?
goRoutine
How can we share resources between concurrent threads in Go ?
Using “channels”
How Go lang generate OS specific binaries for Windows, OS X and Android?
Go uses following variables to create Platform specific binaries:
1. GOOS
2. GOARCH
Once we set these environment variables, Go automatically creates the OS specific binaries. e.g.
1. Windows: GOOS: windows & GOARCH: amd64
2. OSX: GOOS: darwin & GOARCH: amd64
3. Android: GOOS: android & GOARCH: arm
Which package in GO is used to accept command line parameters ?
“Flag”
What should be the first statement of any Go Source File ?
“package” statement.
It says where our source code sits in our Application.
How to put a single line comment in Go ?
// This is a commented line
How to put a multi-line comment in Go ?
/*
This is
multi line comment.
*/
What is an Import statement ?
Import statement is used to import “external” package inside our package.
What is an Import block ?
An import block allowed us to import multiple packages without repeating the word “import”. e.g.
import (
“os”
“fmt”
)
What type of indentation is used by Go formatter to format the code - “Space” or “Tab”?
“Tab”.
It is a standard practice to use “Tab” for indentation, instead of “spaces”
Do GO compiler throws error, if indentation is not provided by the user ?
No
Indentation should be used for code readability but it is not mandatory.
Is it required to use semicolon at the end of each statement ?
No
Go compiler replaces the “new line” character with “semicolon”, so that it is not required by the user to put it at the end of each statement.
What is wrong with following code ?
func main()
{
fmt.Println(“hello”)
}
The line “func main()” will be considered as a “statement”, hence Go compiler will put a Semicolon after this. Hence after compilation it will be look like this
func main();
{
fmt.Println(“hello”)
}
Hence we will get two errors for this:
1. function main without body
2. Semicolon is missing
what is the sub command used for getting the “version” ?
go version
In above “go” is the command and “version” is the subcommand
How to find out documentation about any “subcommand” in Go ?
“help” subcommand.
»> go help doc
What is done by “run” subcommand ?
- Compiles the code
- Create a temporary “executable file” current directory
- Executes the “temporary executable file”
- clean the local workspace