Go Intro

An Introduction to Golang (Go)

Samer AbuNasser / @snassr_

Hello There!

I work for Archetype Consulting


Solutions Architect by Day

Computer Scientist the rest of the time


Golang Enthusiast.

Why Go?

  1. Easy to learn
  2. Built for the Web
  3. Community Oriented by Design
  4. High level & Low level Capabilites
  5. Small & Simple, yet Complete

What Can Go Do?

  • Websites (yes JavaScript will still be involved)
  • Mobile Applications
  • Systems Programming
  • ...

History of Go

  • Originated as an experiment at Google by Robert Griesemer, Rob Pike & Ken Thompson
  • Goal: Development speed of Python with the performance and safety of C or C++
  • Created at Google in 2007

Design Principles I

Regular & Simple

  • Few Keywords
    • if, range, for, else ... (21 more)
  • Main Primitive Types
    • boolean, numerics (uint0x, int0x, float0x, complex0x), strings
  • Main Non-Primitive Types
    • arrays, slices, maps, structs, pointers, functions, interfaces, channels, method sets
  • Statically Typed
    • reduces runtime type errors
    • Compiler enforced variables and imports (YAGNI)
  • Dyanamic Features
    • Fast Compilation
    • Garbage Collection & Cross Plaftform

Design Principles II

Design Abstractly, Code Instinctively

  • Composition over Inheritance
    • No Inheritance; Less planning, Better Extensibility
  • Program to interfaces, not implementations
    • Interface programming is a staple and is fundamentally simple.
  • Polymorphism
    • Interface Methods, Embedded Structs (Subtyping) & Identifier Promotion (Overriding)

Design Principles III

Page Light, Style Consistent

Encourages code that is easier to read and maintain
  • Style can be enforced by the language
    • Gofmt tool to format your code, Godoc tool to document your code
  • Documentation generated by the language
    • Godoc tool to create documentation based on simple commenting rules

Design Principles III Continued

Page Light, Style Consistent

Dynamic & Concise Syntax

// This sample program demonstrates a simple web server.
package main

import (
    "net/http"
)

func main() {
    fs := http.FileServer(http.Dir("/home/me/mywebsite/static/"))
    
    http.Handle("/", fs)
    
    http.ListenAndServe(":3000", nil)
}
                            

Lightening Lessons in Basic Go

Hello World!

Go to play.golang.org

Variables

Go to play.golang.org

Arrays

Go to play.golang.org

Slices

Go to play.golang.org

Structs

Go to play.golang.org

Out of Scope Topics

(Future Talks?)

  1. Pointers
  2. Maps
  3. Multi-Dimensional Structures
  4. Go Types In Depth
  5. Packaging, Project Structure & Tooling
  6. OOP: Composition, Interfaces, Polymorphism...
  7. Concurrency
  8. Cgo
  9. Gotchas
  10. ...

Great Resources

Where to go after this?

  1. Official Golang Website
  2. Blogs & Community
  3. Books

Thanks & Go For It!