Go For The Nodist

 

Sam Clark

Iced Development(https://iceddev.com)

DevOps/Developer

@samrocksc

samrocksc@gmail.com

Why Learn Another Language.....Javascript will be around forever.

My Approach In Picking Go

  • Easy to learn
  • Strongly typed
  • Usable on the backend
  • Strong support
  • Concurrency for heavier tasks
  • Easy maintenance
  • Easy Deployment
  • Low Code Smell!!

What it is

GoLang is a C derivative language that was built to make programming easier, and easier to understand.  It's toolchain was built around creating a developer friendly ecosystem.  It's very cute too.

What it is not

Go is not a frontend language.  It can be used for it, but there are situations where GoLang can be easier to use than Javascript....

Targeting Architectures!

Need to fit a specific architecture to run your code?  No Problem!

GOOS=freebsd GOARCH=arm GOARM=7 go build -v example.go

Cool Features

  • Concurrency Built In!
  • Generates an executable!
  • STLIB! STLIB STLIB!
  • Tools to make things dummy proof

Go Format Yer Code!

go fmt

Let's make a variable

// JayvaScript
var hello = 'Hello!';
const there = 'I am';
let name = 'Sam';



// GoLang
var hello string
hello = 'Hello!'

there := 'I am'
name := 'Sam'

Let's Make A Loop!

// JazzzzzyScript
for (var i = 0; i < 10; i++) {
    console.log(i);
}

vs.

// GoLang
for i := 0; i < 10; i++ {
    fmt.Println(i)
}

Go and Javascript are very similar in a lot of ways....but not too similar

Let's Export A Function

// I am an exported function	
func Add(x int, y int) int {
  return x + y
}

// I am a local function
func subtract(x int, y int) int {
  return x - y
}

Exporting is done by simple capitalization!

STLIB STLIB STLIB!

Standard Library Goodies

  • net/http - High Level Web Interfaces
  • encoding/json - Use things from those interfaces
  • os/exec - Interact with executables on the OS.
  • sync - Interact with go routines and asynchronous code.

In node, native-bindings can throw a huge wrench in gears and cause issues at build time.

Ugh, node-gyp wants to compile again!!!

In go, we can leverage the executable package system, and our binaries to create quicker easier methods of execution on our server.

The Tooling Rules

Tooling for different editors is really nice!  Built in Go Commands provide a smooth devloper atmosphere across all editors

User Friendly Tools

  • go fmt(kiss those spacing issues goodbye)
  • go build(test that build process in an 1/8th of the time
  • go test(fast enough to build and test on every save)

User Friendly Tools

  • go fmt(kiss those spacing issues goodbye)
  • go build(test that build process in an 1/8th of the time
  • go test(fast enough to build and test on every save)

Ecmascript

ES6, Typescript, ES6 flag 0, vanilla, node, bleeding edge, coffee script.

 

....YOU ARE BUILDING THE TOWER OF BABEL!

Golang

No transpilation(this shouldn't be a word), predictable formats.  Consistent error handling

Concurrency

"The Muscle"

Javascript is AWESOME

.....at I/O

Javascript

Event Loop driven concurrency can lead to malfunctions and weird error handling.  Running on a queing system we still don't have a true concurrency.  Great for I/O, but maybe not for....heavier processing?  

GoLang

Go routines allow us to kick off a separate process with a heavier workload.  Returning when finished we can keep our primary chain of programming running while we wait for our go routines to return their data.  Channels allow us to move data between two go routines, allowing for stacks on stacks of uninterrupted processing!

Some Code...

package main
import "fmt"
func f(from string) {
    for i := 0; i < 3; i++ {
        fmt.Println(from, ":", i)
    }
}
func main() {
    f("direct")
    go f("goroutine")
    go func(msg string) {
        fmt.Println(msg)
    }("going")
    var input string
    fmt.Scanln(&input)
    fmt.Println("done")
}

* https://gobyexample.com/gouroutines

Maintenance

maintaining a go project

Javascript

Different linters can leave different methods of doing things.  Which is great, for the same developer for a long time....

Go

go fmt gives us a standardized method of doing things.  Most editors are symbiotically linked to generating documentation.

Deployments

(It's an executable)

Deploying GoLang

  • Typically one file that has been tested as it was compiled.
  • May include config files or .tmp, but not necessary

node.js API

go API

...deploys as one executable with environment variables

...deploys as fifteen thousand five hundred and eighty six files

What Could Go Wrong!

Things I Couldn't Touch On

  • GoDoc(documentation prime)
  • Writing Go(live coding....ew)
  • Package Management
  • Architecture of a package

Resources I used

  • https://gobyexample.com
  • https://godoc.org/
  • https://golang.org/doc/
  • Youtube Videos
  • https://github.com/avelino/awesome-go

Thanks!

Sam Clark

@samrocksc

samrocksc@gmail.com

https://shoutinginfrench.com

GoLang For The Nodist

By Sam Clark

GoLang For The Nodist

Yeahh

  • 950