Loading...

Go, Go Everywhere!


Lately, I’ve been hearing a lot about Go. After seeing it few thousands times I decided to give it a try. I’d like to share my thoughts about learning my process.

What’s that?

Go (often referred to as golang) is a free and open source programming language created at Google in 2007 by Robert Griesemer, Rob Pike, and Ken Thompson. It is a compiled, statically typed language in the tradition of Algol and C, with garbage collection, limited structural typing, memory safety features and CSP-style concurrent programming features added. by Wikipedia

Ok, that looks interesting.

It’s multiparadigm language, static-typed language. That’s quite concerning for me because I’m afraid that there won’t be ‘the proper way’ of doing things and everyone will do in a different way. There is a chance, that people will solve same problems in the scope of one project many times, and won’t know that it’s already solved.

Talk is cheap. Show me the code

I’ve started learning with A Tour of Go and I’ll share interesting(for me) parts of language.

func main() {
    fmt.Printf("Now you have %g problems.", math.Sqrt(7))
}

I’ve spent a lot of time with ruby, javascript, elixir and python. Declaring types is forgotten art of programming for me!

func add(x int, y int) int {
    return x + y
}

Setting type after a name of parameter looks totally weird. Hope I’ll get used to it.

func swap(x, y string) (string, string) {
    return y, x
}

func main() {
    a, b := swap("hello", "world")
    fmt.Println(a, b)
}

I’ve remembered one of my university classed where I had to implement returning few values from the function. It was a quite hard task for someone who didn’t use arrays too much.

func split(sum int) (x, y int) {
    x = sum * 4 / 9
    y = sum - x
    return
}

I don’t like this part. I had a little `WTF` looking at it for the first time… and second… and third… It’s still weird. I prefer to have explicit return value.

var i, j int = 1, 2

func main() {
    var c, python, java = true, false, "no!"
    fmt.Println(i, j, c, python, java)
}

This code returns `1 2 true false no!`.

It’s pretty weird. I don’t know if I like it. I’m quite happy that I don’t have to declare types always, but assigning values like that… is weird. Just weird.

I’d prefer it to be something like `var c=true, python=false, java=”no”` .

func main() {
    var i int
    var f float64
    var b bool
    var s string
    fmt.Printf("%v %v %v %q\n", i, f, b, s)
}

I had a feeling that all value would be `nil`. Actually, they’re not because they’re not pointers but actual values.
The code above returns `0 0 false “”`.

T.B.C.

That’s all for today. There were some weird and intriguing things from language basics. I don’t like it at the moment because everything looks so weird and unfamiliar for me. Learning functional elixir was easier for me.

I won’t give up and hopely I’ll continue this serie about learning go

One thought on “Go, Go Everywhere!

Leave a Reply

Social media & sharing icons powered by UltimatelySocial