Giter Club home page Giter Club logo

golang-book's Introduction

An Introduction to Programming in Go

Notes and code sampesl for the first meeting of the Squaremouth book club. Covering Chapters 1 - 5 of the go lang book.

Chapter Notes

Chapter 1

Nothing of note in this chapter.

Chapter 2 - Your First Program

Finally get to a "Hello World". Briefly explains packages ("main"), importing, and main. Some of the simplest types are broken down.

Chapter 3 - Types

Starts of by explaining types in terms of philosophers and mathematics (man after my own heart).

Integers

  • uint8, uint16, uint32, uint64,int8,int16,int32,int64
  • Alias types: byte == uint8 and rune == int32
  • Machine specific: uint, int, uintpr

Non-integer Numbers

  • float32 and float64 (increase in precision with bits).
  • NaN
  • โˆž - (OPTION + 5)
  • complex64 and complex128

Strings

  • Can be created with "" - Single line strings that allow escape characters
  • Can be created with `` - Multi-line strings but no escape characters
  • len("String") - String length
  • "Sample"[0] - String indexing, does not return what you'd expect

Booleans

  • true, false - literals
  • &&, ||, ! - operations

Chapter 4 - Variables

Now we start looking at how we can declare variables in go. There are a few different ways to do the same thing.

  • var x int = 8 - declaring and assigning in one line
  • var x int - only declaring followed by x = 18 later on
  • x := 8 - assigning and inferring the type
  • const stuff string - Declaring a constant variable, can't be re-assigned

Chapter 5 - Control Structures

Can almost write a useful program now.

Loops

All loops are written in terms of for

  • for stuff == true { ... } - While loop equivalent
  • for i := 1; i <= 5; i += 2 { ... } - Traditional for-loop
  • Yet to be seen for-each style loop

Conditionals

Standard conditionals using real english words.

  • if, else if, else - Main conditional statements
  • switch statement also exists

Discussion Points

  • Capital lettered function/method names. ex)

    fmt.Println("Hello World")
  • The go tool and the godoc command. Run go help to see what it can do.

  • Go has a metric ton of types. Is this worth it?

  • You can use UTF-8 characters, think about that. Show gomega.

  • Go will not allow you to declare variables that aren't used (_ values)

golang-book's People

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.