การเขียนโปรแกรมด้วยภาษา Elixir
คู่มือที่ครอบคลุมเกี่ยวกับการเขียนโปรแกรมเชิงฟังก์ชันและแบบขนานด้วยภาษา Elixir โดยครอบคลุมการเปลี่ยนจากแนวคิดเชิงวัตถุไปสู่การคิดในเชิงฟังก์ชัน การจับรูปแบบ การไม่เปลี่ยนแปลงข้อมูล โมเดลผู้กระทำสำหรับการประมวลผลพร้อมกัน และการสร้างระบบกระจายที่มีความทนทานด้วย OTP
ภาพรวมคอร์สเรียน
📚 สรุปเนื้อหา
คู่มือที่ครอบคลุมเกี่ยวกับการเขียนโปรแกรมแบบฟังก์ชันและพร้อมใช้งาน (concurrent programming) โดยใช้ภาษา Elixir ครอบคลุมการเปลี่ยนจากแนวคิดเชิงวัตถุ (object-oriented) มาเป็นแนวคิดเชิงฟังก์ชัน การจับคู่รูปแบบ (pattern matching) ความไม่สามารถเปลี่ยนแปลงได้ (immutability) โมเดลผู้กระทำ (actor model) สำหรับการประมวลผลขนาน และการสร้างระบบกระจายที่มั่นคงด้วย OTP
เชี่ยวชาญศิลปะในการสร้างระบบที่ทนทานและทำงานพร้อมกันผ่านความงามของโปรแกรมเชิงฟังก์ชัน
ผู้เขียน: เดวิด โทมัส
คำขอบคุณ: โจเซ่ วาลิม, คอรี แฮนส์, บรูซ เทต, เจนนิเฟอร์ เคอร์ร์, แอนโธนี อีเดน, เชด ฟาวเลอร์, คิม ชไรม์, แคแนซ คันนิงแฮม และ พอโตมาค อินเด็กซ์
🎯 เป้าหมายการเรียนรู้
- เปรียบเทียบแนวทางการเปลี่ยนแปลงข้อมูลของภาษา Elixir กับการเขียนโปรแกรมแบบพึ่งพาสถานะ (state-based) ทั่วไป
- ตั้งค่าชัลล์อินเตอร์แอคทีฟของภาษา Elixir (IEx) และรันโค้ด Elixir ผ่านสคริปต์และคอมไพเลอร์
- ใช้ตัวดำเนินการจับคู่ (
=), ตัวดำเนินการแนบ (pin operator^), และตัวแทนที่ไม่สนใจ (_) เพื่อแยกโครงสร้างข้อมูลและตรวจสอบข้อมูล - อธิบายผลกระทบทางทฤษฎีและปฏิบัติของการไม่สามารถเปลี่ยนแปลงข้อมูลต่อประสิทธิภาพและจัดการหน่วยความจำ
- ระบุและใช้ประเภทข้อมูลที่มีอยู่ในตัวของภาษา Elixir รวมถึงประเภทค่า (Value), ระบบ (System), และประเภทคอลเลกชัน (Collection)
- ใช้กฎการจำกัดขอบเขตตัวแปร (variable scoping) และการใช้คำสั่ง
withเพื่อจัดการการเปลี่ยนแปลงข้อมูลที่ซับซ้อน - สร้างและเรียกใช้ฟังก์ชันที่ไม่มีชื่อ (anonymous functions) ทั้งแบบปกติและแบบแคปเจอร์ (
&) - ใช้การจับคู่รูปแบบ (pattern matching) และการเรียกซ้ำ (recursion) ภายในโมดูลเพื่อจัดการตรรกะที่ซับซ้อนโดยใช้ฟังก์ชันที่มีชื่อ
- ใช้เงื่อนไขควบคุม (guard clauses) และพารามิเตอร์เริ่มต้น (default parameters) เพื่อควบคุมลำดับการทำงานของฟังก์ชัน
- แยกโครงสร้างและสร้างรายการ: ใช้การจับคู่หัว/ก้อย (head/tail pattern matching) เพื่อสำรวจและสร้างโครงสร้างรายการแบบเรียกซ้ำ
บทเรียน 共 10 课时 · 预计 30.0h
บทเรียน
Lesson
This lesson introduces Elixir as a functional language focused on data transformation, emphasizing the importance of immutability and the use of the pipe operator for clean, predictable code. Students will also learn how Elixir’s actor-based concurrency model uses isolated processes and message passing to ensure thread safety and system scalability.
This lesson introduces the functional paradigm of Elixir, focusing on the core concept of data immutability and the use of pattern matching over variable mutation. Students will learn how to perform data transformations to create new values rather than modifying existing ones, ensuring predictable and thread-safe code.
This lesson explores foundational functional programming in Elixir, focusing on anonymous and named functions, module encapsulation, and the use of the pipe operator for data transformation. Students will also learn to leverage pattern matching and the `with` expression to handle complex, multi-step logic safely and effectively.
AI019: Recursive Lists and Data Structures (Lesson 4) explores the recursive nature of linked lists in Elixir, focusing on head-tail decomposition and the implementation of custom recursive functions. Students will learn to identify base cases, utilize the cons operator, and apply recursive patterns to perform efficient list operations.
This lesson explores the differences between greedy processing with the Enum module and lazy processing with the Stream module in Elixir. Students will learn to implement the Enumerable protocol and apply these concepts to perform memory-efficient data transformations and advanced string processing.
This lesson explores advanced Elixir control flow, focusing on pattern matching with case expressions, guard clauses, and the use of the with construct for error handling. Students will also learn to manage project structures using Mix and improve code quality through professional tooling like Credo and Dialyzer.
This lesson explores how to maintain persistent state in Elixir using recursive functions and Tail-Call Optimization (TCO) to keep processes alive. Students will learn to manage process lifecycles, handle message passing, and implement deterministic communication patterns in concurrent systems.
This lesson explores the fundamentals of the Open Telecom Platform (OTP) in Elixir, focusing on how behaviors, supervision trees, and I/O messaging enable the creation of fault-tolerant, distributed applications. Students will learn to implement GenServers and leverage the Error Kernel philosophy to build robust systems that effectively manage process lifecycles and inter-node communication.
This lesson explores advanced OTP architectures and the Five-Question Framework to achieve high-reliability state management in Elixir. Students will learn to design robust supervision trees and distributed systems by systematically defining environment constraints, focal points, and fault-tolerance strategies.
This lesson explores Elixir’s metaprogramming capabilities, focusing on how the language's homoiconic nature allows source code to be treated as data via the Abstract Syntax Tree (AST). Students will learn to design extensible software using protocols and macros while evaluating how static analysis tools like Dialyzer provide type safety without sacrificing dynamic flexibility.