เริ่มต้นเขียนโปรแกรมด้วยภาษา Go
บทเรียนที่เหมาะกับผู้เริ่มต้นและมีประสบการณ์จริงเกี่ยวกับภาษาโปรแกรมมิ่ง Go โดยจัดเป็นบทเรียนเล็กๆ ที่จัดการได้ง่าย มีธีมการสำรวจอวกาศ ครอบคลุมหัวข้อการเขียนโปรแกรมแบบบังคับ ชนิดข้อมูล ฟังก์ชัน เมธอด เซ็ตข้อมูล สถานะ และการประมวลผลพร้อมกัน
ภาพรวมคอร์สเรียน
📚 สรุปเนื้อหา
บทเรียนที่เข้าใจง่ายและใช้งานจริงสำหรับผู้เริ่มต้นกับภาษาโปรแกรม Go หลักสูตรนี้จัดทำเป็นบทเรียนเล็กๆ ที่จัดการได้ พร้อมธีมการสำรวจอวกาศ ครอบคลุมหัวข้อเกี่ยวกับการเขียนโปรแกรมเชิงบังคับ ประเภทข้อมูล ฟังก์ชัน เมธอด โครงสร้างข้อมูล สถานะ และความขนาน (concurrency)
ค้นพบความสนุกของการเขียนโค้ดด้วยภาษา Go ผ่านบทเรียนเล็กๆ และโครงการปลายทางทั้งหมด 7 โปรเจกต์ที่เกี่ยวข้องกับการเดินทางในอวกาศ
ผู้เขียน: นาธาน ยังแมน, โรเจอร์ เปปเป้
ขอบคุณ: เจนนิเฟอร์ สตาวต์, มารีนา มิคาเอลส์, เมธาเวอร์ มิร์เคส, โจเอล โคตาร์สกี, อเล็กซานดาร์ ดรากอสฟเยวิช, รีนี ฟรานซ์, โอลกา ชาลาฆินา, เอริก ซีลยา, เอบริล มิลน์, มอนิกา แคมสวาอา
🎯 เป้าหมายการเรียนรู้
- นิยามภาษาโปรแกรม Go และกรณีการใช้งานหลักของมัน
- อธิบายบทบาทของคอมไพเลอร์ภาษา Go และข้อดีเหนือตัวแปลโปรแกรม (interpreter)
- ใช้งาน Go Playground เพื่อเขียน คอมไพล์ และรันโค้ด
- จัดโครงสร้างโค้ดภาษา Go อย่างถูกต้องตาม "สไตล์เครื่องหมายวงเล็บแบบเดียว" ที่จำเป็น เพื่อหลีกเลี่ยงข้อผิดพลาดทางไวยากรณ์
- จัดการข้อมูลโดยใช้เทคนิคการประกาศตัวแปรต่างๆ และตัวดำเนินการรวมค่าทางคณิตศาสตร์
- สร้างเลขสุ่มเทียม และนำตรรกะเงื่อนไขมาใช้ผ่านการแยกทาง (branching) และตัวดำเนินการตรรกะ
- ประกาศและจัดรูปแบบตัวแปรทศนิยมโดยใช้
float32และfloat64พร้อมขนาดและความแม่นยำเฉพาะ - ระบุและลดผลกระทบจากข้อผิดพลาดที่เกิดจากความไม่แม่นยำของเลขทศนิยมและค่าเต็มที่เกินขอบเขต (integer wrap-around)
- ใช้แพ็กเกจ
bigและค่าคงที่ไม่มีประเภท (untyped constants) เพื่อจัดการกับจำนวนที่เกินขีดจำกัดขนาดบิตมาตรฐาน - กำหนดและเรียกใช้ฟังก์ชันโดยใช้พารามิเตอร์ อาร์กิวเมนต์ และไวยากรณ์แบบตัวแปร (variadic syntax)
บทเรียน 共 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.