Intro

I’ve been casually looking into the go language without trying it much. Now it’s time to write so go code :)

Golang

Looping

First discovery there is no while keyword in golang, I was pretty surprised I thought I was missing something.
I then look in the spec and there is only for.
I like that they only have limited number of keywords.

i := 0
for i < 10 {
    fmt.Println(i)
}

Return statements

Return statement can be specified in function definition
E.g:

func returnByDefault(s string) (first string, second string) {
	first = "test"
	return
}

So even if it looks like nothing is returned, it will return first if declared in the function.
If we run the function above it will return “test”.

Init

I thought main was the first entry point in golang, looks like if a function is called init it will be called before.

func init() {
	fmt.Println("Executed before main")
}

Datatypes

Not sure if I will get used to declaring types after variable name, well will see.

func declaringPrimitivesDatatypes() {
	var s string
	var b bool
	var i uint16
	s = "test"
	b = true
	i = 1
	fmt.Println(s, b, i)
}

I prefer the short assigment variable declaration:

	c, python, java := true, false, "no!"
	fmt.Println(c, python, java)

That’s it for today, more to come very soon.