Get Programming with Go
A beginner-friendly, hands-on introduction to the Go programming language. The course is structured into small, manageable lessons with a space-exploration theme, covering imperative programming, types, functions, methods, collections, state, and concurrency.
Pelajaran
Gambaran Umum Kursus
📚 Content Summary
A beginner-friendly, hands-on introduction to the Go programming language. The course is structured into small, manageable lessons with a space-exploration theme, covering imperative programming, types, functions, methods, collections, state, and concurrency.
Discover the joy of coding with Go through small lessons and seven spacefaring capstone projects.
Author: Nathan Youngman, Roger Peppé
Acknowledgments: Jennifer Stout, Marina Michaels, Matthew Merkes, Joel Kotarski, Aleksandar Dragosavljević, Renée French, Olga Shalakhina, Erick Zelaya, April Milne, Monica Kamsvaag.
🎯 Learning Objectives
- Define the Go programming language and its primary use cases.
- Explain the role of the Go compiler and its advantages over interpreters.
- Navigate the Go Playground to write, compile, and run code.
- Correctly structure Go code using the mandatory "one true brace style" to avoid syntax errors.
- Manage data using various variable declaration techniques and arithmetic assignment operators.
- Generate pseudorandom numbers and implement conditional logic using branching and logical operators.
- Declare and format floating-point variables using
float32andfloat64with specific width and precision. - Identify and mitigate errors caused by floating-point inaccuracies and integer wrap-around.
- Utilize the
bigpackage and untyped constants to handle numbers exceeding standard bit-size limits. - Define and invoke functions using parameters, arguments, and variadic syntax.
🔹 Lesson 1: Launching into Orbit
Overview: This lesson introduces Go, the contemporary programming language of cloud computing. Students will learn the fundamental difference between Go's compiled nature and interpreted languages, how to use the Go Playground for immediate experimentation, and the basic structure of a Go program involving packages and the main function.
Learning Outcomes:
- Define the Go programming language and its primary use cases.
- Explain the role of the Go compiler and its advantages over interpreters.
- Navigate the Go Playground to write, compile, and run code.
🔹 Lesson 2: Mission Control Logic
Overview: This lesson introduces the fundamental building blocks of Go programming, focusing on how to structure code and control its execution. Students will learn the "one true brace style" and program entry points, progress through variable declaration shortcuts and mathematical operators, and conclude with decision-making logic using Booleans, comparisons, and branching.
Learning Outcomes:
- Correctly structure Go code using the mandatory "one true brace style" to avoid syntax errors.
- Manage data using various variable declaration techniques and arithmetic assignment operators.
- Generate pseudorandom numbers and implement conditional logic using branching and logical operators.
🔹 Lesson 3: The Physics of Space Data
Overview: This lesson explores how Go handles numerical data, ranging from the fractional precision of floating-point numbers to the massive scales required for astronomical distances. Students will learn to manage the limitations of computer memory, including floating-point inaccuracies and integer wrap-around, while mastering explicit type conversion and the use of the big package for "unusual" numeric sizes.
Learning Outcomes:
- Declare and format floating-point variables using
float32andfloat64with specific width and precision. - Identify and mitigate errors caused by floating-point inaccuracies and integer wrap-around.
- Utilize the
bigpackage and untyped constants to handle numbers exceeding standard bit-size limits.
🔹 Lesson 4: Building Modular Modules
Overview: This lesson covers the fundamental building blocks of Go programs: functions, custom types, and methods. Students will learn how to encapsulate logic for reuse, define new types with specific behaviors, and leverage first-class functions—including closures and anonymous functions—to create flexible and modular code. The lesson concludes with a practical capstone project involving temperature conversion tables.
Learning Outcomes:
- Define and invoke functions using parameters, arguments, and variadic syntax.
- Distinguish between exported and unexported identifiers using Go’s naming conventions.
- Create custom types and attach behaviors to them using methods and receivers.
🔹 Lesson 5: Stocking the Cargo Bay
Overview: This lesson covers the essential data structures in Go for managing collections of information. It transitions from fixed-length arrays and their memory-copying behavior to dynamic slices that serve as flexible windows into data, and finally to maps for efficient key-value lookups. The unit culminates in the "Game of Life" capstone, which demonstrates how to use multi-dimensional slices to simulate complex systems.
Learning Outcomes:
- Declare, initialize, and iterate through fixed-length arrays and multi-dimensional grids.
- Manipulate slices using index ranges and dynamic growth via the
appendfunction. - Manage memory efficiency by distinguishing between length and capacity and preallocating collections with
make.
🔹 Lesson 6: Structuring Martian Habitats
Overview: This lesson introduces Go’s approach to organizing complex data and behaviors. Students will learn how to group disparate data types into structures (structs), initialize them using composite literals, and manage their behavior through methods and constructor functions. The lesson also explores Go's unique design philosophy: favoring composition over inheritance and using implicit interfaces to achieve polymorphism.
Learning Outcomes:
- Define, initialize, and copy structures to manage complex Martian coordinate and rover data.
- Encode Go structures into JSON format using struct tags for customized data interchange.
- Implement methods, constructor functions, and struct embedding to build reusable and organized code.
🔹 Lesson 7: Navigating the Gopher Hole
Overview: This lesson explores the power and safety of indirection in Go, focusing on how pointers allow for efficient data mutation and memory management. It provides a robust framework for defensive programming by teaching students how to handle nil values, manage resources with defer, and implement idiomatic error handling patterns—culminating in the application of these rules to a Sudoku validation engine.
Learning Outcomes:
- Use the ampersand (
&) and asterisk (*) to manage memory addresses and dereference values. - Implement pointer parameters and receivers to enable data mutation in functions and methods.
- Navigate
nilvalues across slices, maps, and interfaces without causing runtime panics.
🔹 Lesson 8: Multi-Rover Communications
Overview: This lesson introduces the core concurrency primitives in Go: goroutines and channels. It explores how to run tasks independently, communicate safely between them, and manage shared state using Mutexes to avoid race conditions. The lesson concludes with a capstone project simulating Mars rovers navigating a grid and reporting discoveries.
Learning Outcomes:
- Launch and manage concurrent tasks using the
gokeyword. - Implement safe communication between goroutines using channels and the
selectstatement. - Construct data pipelines and manage goroutine lifecycles by closing channels.