用 Go 程式設計
一門適合初學者的實作導向課程,介紹程式語言 Go。課程以太空探險為主題,分為許多小而易管理的單元,涵蓋指令式程式設計、資料型別、函式、方法、集合、狀態與並行處理。
課程總覽
📚 內容概要
一門適合初學者的實作導向課程,介紹 Go 程式語言。本課程以太空探險為主題,分為小而易於管理的單元,涵蓋指令式程式設計、資料類型、函數、方法、集合、狀態與並行處理。
透過小型課程與七個太空探索專題,發現使用 Go 編程的樂趣。
作者: Nathan Youngman, Roger Peppé
致謝: Jennifer Stout, Marina Michaels, Matthew Merkes, Joel Kotarski, Aleksandar Dragosavljević, Renée French, Olga Shalakhina, Erick Zelaya, April Milne, Monica Kamsvaag。
🎯 學習目標
- 定義 Go 程式語言及其主要應用場景。
- 解釋 Go 編譯器的角色及其相較於解譯器的優勢。
- 使用 Go Playground 來撰寫、編譯並執行程式碼。
- 正確運用「唯一正確的大括號風格」來結構化 Go 程式碼,避免語法錯誤。
- 使用多種變數宣告方式及算術賦值運算子來管理資料。
- 產生偽隨機數,並利用分支與邏輯運算子實現條件判斷邏輯。
- 使用
float32與float64來宣告與格式化浮點變數,並設定特定寬度與精確度。 - 識別並化解因浮點數不精確性與整數溢位所導致的錯誤。
- 利用
big套件與無類型常數來處理超出標準位數限制的數字。 - 使用參數、引數與可變參數語法來定義與呼叫函數。
課程 共 8 课时 · 预计 24.0h
課程
Lesson
This lesson introduces Go as a high-performance, open-source language designed for cloud-native infrastructure and large-scale software engineering. Students will explore Go's core pillars of simplicity, efficiency, and reliability, and learn how its compiler facilitates error detection and maintainable code for complex distributed systems.
This lesson introduces the fundamentals of imperative programming in Go, focusing on the mandatory main package and func main() entry point. Students will also learn the importance of Go’s "One True Brace Style" and how the compiler's automatic semicolon insertion rules dictate specific syntax requirements.
This lesson explores the limitations of binary floating-point arithmetic in Go, explaining why decimal fractions like 0.1 cannot be represented precisely due to base-2 conversion errors. Students will learn to navigate the trade-offs between float32 and float64, emphasizing the importance of avoiding floating-point types for financial calculations and using appropriate precision for scientific data.
This lesson explores the principles of modularity in Go, focusing on how functions, abstraction, and the DRY (Don't Repeat Yourself) principle improve code maintainability and reduce complexity. Students will learn to define clear module boundaries and interfaces to build robust, scalable software systems.
This lesson introduces arrays in Go as fixed-length, type-specific collections used to manage bulk data efficiently. Students will learn how to use composite literals for initialization, navigate zero-based indices, and understand the importance of memory safety to avoid runtime panics.
This lesson introduces Go structures (structs) as a method for grouping disparate data types into cohesive, atomic units for better organization. Students will learn to define and manipulate these structures to manage complex telemetry data, such as Martian habitat coordinates and rover status, more effectively than with individual variables.
This lesson explores the concept of indirection in Go, focusing on how pointers store memory addresses to manage shared data efficiently. Students will learn to use the address operator (&) and dereference operator (*) to manipulate data, while applying these concepts to build performant, shared-state structures like a Sudoku validator.
This lesson explores concurrency in Go, focusing on using goroutines to manage independent tasks and synchronization tools like mutexes and select statements. Students will learn how to handle non-deterministic execution and implement robust worker patterns for multi-agent systems.