---
# System prepended metadata

title: is Go for you? Talk Summary
tags: [Talks]

---

# is Go for you? Talk Summary
###### tags: `Talks`

This talk is conducted by Siu Yin during GoLang 10th Anniversary, 20 November 2019 at Google Singapore.

- [Event Details](https://www.meetup.com/golangsg/events/266039423/?read=1&_xtd=gatlbWFpbF9jbGlja9oAJDdhYmQ4NTMwLTc5ZWUtNDdjMS05NmY3LTlmOTAzNzQwNGI5Mg&_af=event&_af_eid=266039423) 
- [Presentation and code]( github.com/siuyin/present-is_go_for_you)
- [Video of the talk](https://www.youtube.com/watch?time_continue=63&v=_javfXB7XNg)
- Notes by [@lyqht](https://gist.github.com/lyqht)

---

## What is Go is good for
- writing backend servers
- being simple to read and understand (as compared to C and Java)
- Implicit Interface Satisfaction
- Java done right: cross-platform

> [name=Guest] Q. Can Go be used for Machine Learning?
> [name=Siu Yin] A. Go is very good for data engineering. Go has data flow libraries for cleaning data very fast, but for machine learning itself, Go is not the right tool for it.
> 

> [name=Guest] Q. is Go a good tool for IO-intensive applications?
> [name=Siu Yin] A. Yes! Go is precisely good for these sort of applications. NodeJS is rockin the world with its multiplex but it is still bounded by a single thread. Go is multiplex but you can use all threads!

---
## Features of Go

### Type-safety: very strongly typed
- :heavy_check_mark: Allows comprehensive compile time checks
- :heavy_check_mark: Stable, consistent and predictable atrun-time
- :x: inflexible, rigid, requires a lot of type defining when writing the program
- :x: not dynamic; type not replaceable at run-time 

An example shown about type-safety with Go
![](https://i.imgur.com/qxjioQH.png)

### Implicit Satisfied Interfaces


- You do not have declare `class A implements interface B,C,D,E...`, you can just use its method directly.
- Best example is the IOWriter/ IOReader

An example of implicit satisfied interface 
![](https://i.imgur.com/mO59low.png)

> [name=Guest] Q. Java function interfaces do the same thing right? So what's the point?
> [name=Siu Yin] A. I like to think Go started it first, Java copied it later. XD Javascript, Kotlin, NodeJS the new modern languages are converging to having similar features. Go is designed to be like Python, concise and easily readable. But a lot Python peeps jumped to Go after learning since Python is really slow and has a global interpreter lock. I jumped from Ruby! Ruby is a fantastic and fun language. It has similar issue but is fast enough for me. But because it is so fun to write, 5 years later when I come back to read it, I might not understand it. Go tries to circumvent that problem.

### Built-in Concurrency

- [(webworker $\approx$ java thread) = os-level thread] $\not =$ goroutine
    - A million goroutines can share one thread.
    - GoLang got the idea of goroutines from coroutines, and Javascript Kotlin u name it start copying from GoLang lol

- Go's concurrency is so good that a beginner can write code that can be production-ready like nginx in terms of speed of delivery of requests to a server.
- Go is designed for backend servers

Example: we want to make plus() and dot() run at the same time. Without any statements executed to run 

1. The plus statement hogs the cpu and don't let the rest of the statements run

![](https://i.imgur.com/X1wqTw8.png)
2. Adding a `go` keyword in front of a statement, we incorporate go-routines, and now plus() and dot() can run together! but wait! the print statement for "About to execute select" is still not running! oh we didn't put the `go` for dot(), so let's try doing that.

![](https://i.imgur.com/ncvJn5k.png)
3. We can now see the 2nd print statement! And somehow, it happens before the plus and dots are printed! So what does `select{}` actually do? Let's try commenting it out.

![](https://i.imgur.com/fHOZU5T.png)
4. Without the `select{}`, the go-routines are stopped. and both the statements attached to them are not executed. Go has a very performant garbage collector.

> [name=Siu Yin] Scala is (*insert puking noises*) - i can't read my own code after 1 week

### Go is portable

- Go can compile to JS webassembly binaries XDD and a lot of other platforms. Check it out if you're interested!

### Go memory consumption efficiency
- For Java, class files can be very small but requires the JVM which is 50mb++
- For Go, a small hello world is already 2mb++, and this is because the Entire Go runtime that handles Go routines etc is already embedded in the binary. 
- Most Go modules are self-contained, but stuff like HTTP is possible to make it self contained. Net HTTP/ Net libraries are dynamically linked libraries which use the operating system's resolver library. Go ppl don't like. 
- Go binaries can get big very fast with a small application. But they dont expand in size exponentially. e.g. Entire Docker binary is written in Go, and is about 50mb+.
- Mantra of Go: Don't communicate by sharing memory. Share memory by communicating. Only communicate between different processes using channels.