
Explore the fundamentals of the Go language, including installation, documentation, types, variables, and functions. Master control flow with for loops, switch, slices, maps, structs, pointers, and interfaces.
This lecture covers installing Go on Linux and other OS by downloading the binary tarball, extracting it, and updating the PATH via profile or bashrc to test the install.
Set up a go workspace, export PATH and GOPATH in your shell, create hello.go, compile with go install, and run the hello binary to verify installation that prints hello world.
Learn how Go packages organize code, using package main and the main function to print Hello world, and inspect the fmt package with go doc and go tool.
Introduce Go data types and declarations, covering int, uint, byte, rune, floats, complex, strings with quotes or backticks, booleans, and zero-based arrays; explain var and short declaration with type inference.
Explore Go program structure with a hello world example, using package main and the main entry point, and fmt.Printf for formatted output. Learn global var declarations and type inference.
Declare multiple variables on a single line in Go using inline declarations and the colon equal syntax, with A and B set to 3 and 5.
Learn to define a new function that adds two integers and returns the sum. Call the function from main, pass parameters, and apply the return type and curly brace syntax.
Learn how to swap two integers in Go using a temporary variable and direct assignment, then return multiple values from a function to update a and b.
Name the return values x and y in a Go function and see how named returns assign them and remove the explicit return.
Learn how to implement a variadic parameter list in Go to sum any number of integers, using ellipsis, a for loop, and a return value.
Learn how recursion works in Go by using a self calling factorial function, with a base case that factorial of 0 is 1, and understand stack growth and overflow risks.
Explore arrays in Go, sum scores with a for loop, and compute the average by dividing by the array length, noting zero-based indexing and two-decimal formatting.
Explore how the Go for loop combines initialization, condition, and post‑increment in three forms, compare i++, i+=1, and practice forward and backward looping.
Explore using range to iterate over a Go array and obtain its length with len. Cast integers to float64 to compute the average.
Learn to implement decisions in Go using if, else if, and else with boolean conditions and equality checks, printing outcomes for equal, not equal, and other comparisons.
Explore how Go's switch replaces if-else for grading, using range-based cases and fall-through to assign letter grades from scores.
Explore Go control flow by using a for loop to iterate numbers and a switch on a size variable to classify inputs as small, medium, or large.
Streamline Go switches by removing unnecessary code, using multi-case syntax and a default to classify numbers as small, not small but not large, or large.
Explore how slices in Go act as views into arrays with length and capacity, created with make, and how append and slicing ranges reveal and modify their contents.
Explore how to append values to slices in Go, including appending multiple items and a slice to another using an ellipsis and variadic parameters.
Extract the first word from a string in Go by returning a slice of bytes. Iterate through the string, stop at the first space, append characters, and return the result.
Explore how maps in Go map keys to values, using hashable keys and unique values. Declare and initialize with make, and check key existence with the comma ok idiom.
Learn how to define and use structures in Go, including a rectangle with width and height, its area function, and how pointers and the indirection operator operate on struct values.
Explore how pointers store memory addresses and enable indirection with the star and ampersand operators. Learn how new allocates space and how passing pointers to functions lets you modify values.
Explore pointers in Go by creating a pointer to int, printing address and contents, and showing how copied pointers share memory and enable passing to functions to alter values.
Explore passing values by value and by reference in Go, using pointers to modify a variable in place, with examples of negating a number via address and the ampersand operator.
Learn to read strings from stdin in Go using buffered input and output with NewReader, terminating on newline, and handling errors.
Learn how to read user input in Go using the format package’s scan, scanln, and scanners, including pointer-based destinations, counts, and error handling, with examples for words and integers.
Explore go structures and methods. Initialize a point with make point or new, return pointer, and compute distance using a method, while the dot operator works for values and pointers.
Use defer to postpone work until a function ends, enabling cleanups like closing a file. Understand that deferred calls push onto a stack and execute in last-in, first-out order.
Learn how function types in Go treat functions as values, creating closures that capture outer variables like a and b, enabling a+b via a typed function assigned to a variable.
Explore how closures close over local variables and scope to generate the Fibonacci sequence, returning a function that yields successive unsigned integers and retains previous values.
Explore how Go interfaces let different types describe themselves through a single contract. Implement the describe method on circle and cylinder to reveal radius, area, circumference, and volume.
This course teaches the fundamentals of programming in the Go language. Go is a language suitable for a wide variety of tasks, from systems programming to writing web servers. In this course, we’ll learn the syntax of Go, but more importantly, how to “think in Go.” While many tasks can be performed in the same ways as they are done in other programming languages, there is usually a more streamlined solution offered by Go, and that’s what we’re here to learn.
This 3-hour course is divided into four units. Topics include:
- Installing Go and verifying the installation
- Finding package documentation
- Data types and program structure
- Functions
- Loops and conditional statements
- Arrays and slices
- Maps
- Structures and pointers
- New vs. Make
- Reference types and value types
- Buffered input and output
- Initialization
- Function types and closures
- Interfaces
I hope you join me for this exciting look into one of the most powerful and elegant languages there is!