GoTheBiggerPicture Flashcards

1
Q

Main problems solved by Go-Lang

A
  1. In-efficient Compilation
  2. In-efficient Execution
  3. Complex programming model
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

From Which language syntax is inspired in Go lang?

A

‘C Language’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Is Go procedural or Object Oriented ?

A

It is both.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Is Go Garbage collected ?

A

Yes Go language automatically performs garbage collection.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

what it means when we say Go is fully compiled language?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Does Go provides Single Binary output after compilation ?

A

yes, to make deployment easier, the Go compiler provides single binary output for deployment.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

When first version of Go was released and what’s its release cycle ?

A

First Version: 2012 - 1.0
Release Cycle: Every six Month
Current Version: 1.20

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are the go inbuilt packages which provide network supports?

A

net and net/http

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Which package in Go language provides “concurrency” support ?

A

goRoutine

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How can we share resources between concurrent threads in Go ?

A

Using “channels”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How Go lang generate OS specific binaries for Windows, OS X and Android?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Which package in GO is used to accept command line parameters ?

A

“Flag”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What should be the first statement of any Go Source File ?

A

“package” statement.
It says where our source code sits in our Application.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How to put a single line comment in Go ?

A

// This is a commented line

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How to put a multi-line comment in Go ?

A

/*
This is
multi line comment.
*/

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is an Import statement ?

A

Import statement is used to import “external” package inside our package.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What is an Import block ?

A

An import block allowed us to import multiple packages without repeating the word “import”. e.g.
import (
“os”
“fmt”
)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What type of indentation is used by Go formatter to format the code - “Space” or “Tab”?

A

“Tab”.
It is a standard practice to use “Tab” for indentation, instead of “spaces”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Do GO compiler throws error, if indentation is not provided by the user ?

A

No
Indentation should be used for code readability but it is not mandatory.

20
Q

Is it required to use semicolon at the end of each statement ?

A

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.

21
Q

What is wrong with following code ?
func main()
{
fmt.Println(“hello”)
}

A

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

22
Q

what is the sub command used for getting the “version” ?

A

go version
In above “go” is the command and “version” is the subcommand

23
Q

How to find out documentation about any “subcommand” in Go ?

A

“help” subcommand.
»> go help doc

24
Q

What is done by “run” subcommand ?

A
  1. Compiles the code
  2. Create a temporary “executable file” current directory
  3. Executes the “temporary executable file”
  4. clean the local workspace
25
Q

What is a Go Module ?

A

Go Module is a directory which contains the “go.mod” file. It can be seen as “workspace” or “project directory”.

26
Q

How to initialise a go module ?

A

go mod init <module></module>

27
Q

What is the standard format to name a Go Module ?

A
  1. <repository-domain>/<user-name>/<repository-name>
    </repository-name></user-name></repository-domain>
  2. All Lower Case
    e.g. githib.com/fil/my-repository
28
Q

What is the default content of go.mod file ?

A
  1. Module Name
  2. Go Version
29
Q

How to run an entire Module in Go ?

A

Use module identifier:
go run github.com/my-name/my-repository

30
Q

What is the keyword required to declare a variable ?

A

“var”

31
Q

What is the order of providing type in Variable declaration ?

A

The Type is always provided at the end of declaration in the format
var <variableName> <variableType> e.g.
var i int</variableType></variableName>

32
Q

How to declare and initialise variables in a “single line” with data type ?

A

var <variableName> <dataType> = <value>
e.g. var f float32 = 3.14</value></dataType></variableName>

33
Q

What is the shorthand way to declare and initialise variables without using the “var” keyword and data type

A

<variableName> := <variableValue>
e.g. firstName := "arthur"
</variableValue></variableName>

34
Q

How to do multi variable declaration and initialisation ?

A

This can be only done by using “Shorthand syntax”.
e.g. i, j = 12, 23
(Two names on left side and two values on right side)

35
Q

What’s a pointer variable ?

A

A variable which stores only “address” of another variable.

36
Q

How to declare a pointer variable ?

A

By Using “*” with variable type
e.g. var ptr *string

37
Q

What is the default value of pointer variable without initialisation ?

A

“nil”

38
Q

How to initialise an empty pointer variable ?

A

Using “new” function:
var ptr *string = new(string)

39
Q

What is “referencing” and “de-referencing” ?

A

Referencing: It means pointing to the address of variable
de-referencing: It means pointing to the “value” of the variable

40
Q

How to access the value of a variable, if we have it’s memory address (pointer) ?

A

By using Dereferencing variable.
e.g fmt.Println(*ptr)

41
Q

How to assign a value to the variable, if we have it’s memory address (pointer) ?

A

By using Deferencing variable:
e.g. *ptr = “myValue”

42
Q

How to save address of a variable into pointer variable ?

A

Using “address” variable:
e.g. ptr := &myvar

43
Q

What is a constant ?

A

A variable whose value cannot be changed

44
Q

How to declare a constant implicitly and explicitly ?

A

Implicit Declaration = Type determined as per the value of constant
e.g. const i = 23
Explicit Declaration = Type provided by the programmer
e.g. const i int = 23

45
Q

?What’s the advantage of implicit const declaration ?

A

In Implicit declaration, the compiler automatically changes the type of the varaible based on the operation:
e.g. const i = 2
i + 2 // int + int
i + 2.3 // int + float
In second operation, the compiler will automatically converts the constant into float type and then performs the operation

46
Q

What’s a constant block ?

A

A constant block is a package level block, where we can declare and intialize multiple constants without repeating the word “constant”
e.g const (
first = 23
second = 24
)

47
Q

what is iota keyword ?

A

It’s just a “int” constant sequencing keyword. It increments everytime we declare and use constants.