- عنوان کتاب: Systems Programming with Zig -Build Real Tools with No Hidden Cost
- نویسنده: Mihalis Tsoukalos
- حوزه: برنامهنویسی سیستمی
- سال انتشار: 2026
- تعداد صفحه: 542
- زبان اصلی: انگلیسی
- نوع فایل: pdf
- حجم فایل: 8.25 مگابایت
به ویرایش اول برنامهنویسی سیستمها با زیگ خوش آمدید! برنامهنویسی سیستمها همیشه رشتهای بوده که با صداقت تعریف میشود. صداقت در مورد آنچه سختافزار میتواند انجام دهد. صداقت در مورد اینکه حافظه از کجا آمده و به کجا میرود. صداقت در مورد هزینه هر انتزاع. برای دههها، زبان C زبانی بود که این صداقت را مجسم میکرد – نه به این دلیل که زیبا بود، بلکه به این دلیل که تقریباً هیچ چیز را پنهان نمیکرد. شما اشارهگرها را میدیدید. شما حافظه را مدیریت میکردید. شما دستگاه را زیر انگشتان خود حس میکردید. زیگ این سنت را به جلو میبرد، اما کاری را انجام میدهد که زبان C هرگز کاملاً از عهده آن برنیامد: مسیر صادقانه را به مسیر راحت نیز تبدیل میکند. هیچ جریان کنترل پنهانی وجود ندارد. هیچ تخصیصدهنده سراسری وجود ندارد که بیسروصدا از طرف شما کار انجام دهد. هیچ تصمیمگیری در زمان اجرا وجود ندارد که شما درخواست نکرده باشید. آنچه مینویسید همان چیزی است که اجرا میشود و کامپایلر – با صدای بلند، در زمان ساخت – به شما خواهد گفت که چه زمانی آنچه نوشتهاید با آنچه دستگاه نیاز دارد مطابقت ندارد. این کیفیت، این امتناع از پنهان شدن پیچیدگی در گوشه و کنار، چیزی است که زیگ را به یک زبان واقعاً جالب برای کار سیستمها تبدیل میکند، نه صرفاً یک رقیب دیگر. این کتاب برای برنامهنویسانی است که میخواهند سیستمها را درک کنند، نه فقط از آنها استفاده کنند. ما فرض میکنیم که شما میتوانید کد Zig را بخوانید و در یک ترمینال UNIX حرکت کنید. چیزی که ما فرض نمیکنیم این است که شما از قبل میدانید چرا یک سرور TCP echo در accept() مسدود میشود، زمانبند ورودی/خروجی هسته در حالی که نویسنده بافر شما بایتها را جمعآوری میکند چه کاری انجام میدهد یا چرا انتخاب تخصیصدهنده اشتباه در یک حلقه داغ میتواند به شما ضرر زیادی در توان عملیاتی وارد کند. اینها سوالاتی هستند که این کتاب حول آنها ساخته شده است. ما در کل ابزارهای واقعی میسازیم. یک کلون tee(1)، یک لیستکننده فایل Zip، یک مشاهدهگر فایل با پشتیبانی از اولیههای هسته مخصوص پلتفرم، یک زمانبند کار همزمان، یک حافظه پنهان در حافظه در سطح تولید با یک پروتکل دودویی سفارشی، یک سرویس یادداشتبرداری با پشتیبانی SQLite3 و در نهایت، یک مفسر کارآمد برای یک زبان برنامهنویسی کوچک که از ابتدا ساخته شده است. اینها نمونههای اسباببازی نیستند که به عنوان پروژهها پوشیده شدهاند. آنها نوعی برنامههایی هستند که شما را مجبور میکنند تصمیمات معماری بگیرید، عواقب آن تصمیمات را در خروجی معیار احساس کنید و بفهمید که چرا جامعه سیستمها بر روی الگوهایی که انجام داده است، تصمیم گرفتهاند. طبق سنت متون پایهای مانند محیط برنامهنویسی یونیکس و زبان برنامهنویسی C، ما مرتباً مکث میکنیم تا دلیل آن را بررسی کنیم. وقتی یک mutex را معرفی میکنیم، توضیح میدهیم که بدون آن چه مشکلی پیش میآید. وقتی یک تخصیصدهندهی عرصه را انتخاب میکنیم، جایگزین آن را محک میزنیم. وقتی یک پروتکل دودویی طراحی میکنیم، نشان میدهیم که comptime چه چیزی را میتواند اعمال کند که بررسی زمان اجرا نمیتواند. کد وسیلهای برای درک بدهبستانهای مهندسی است و این بدهبستانها برنامهی درسی واقعی هستند. Zig 0.16.x با تغییرات قابل توجهی از راه رسید – انتزاعات جدید I/O، یک تخصیصدهندهی تغییر نام داده شده، یک API شبکهی بازسازی شده – و این کتاب در کل بر اساس آن نسخه نوشته شده است. هر فهرست کد روی Zig 0.16.0 کامپایل و اجرا میشود. جایی که زبان انتخاب جالبی انجام داده یا از یک قرارداد قدیمیتر جدا شده است، ما این را صریحاً میگوییم، زیرا درک اینکه چرا یک زبان تکامل مییابد، بخشی از درک زبان است. برنامهنویسی سیستمها یک مدرسهی پایانی برای برنامهنویسانی نیست که به هر چیز دیگری تسلط دارند. این یک روش تفکر است – در مورد منابع، در مورد زمان، در مورد شکاف بین آنچه از دستگاه خواستهاید انجام دهد و آنچه واقعاً انجام داده است. زیگ یک لنز فوقالعاده واضح برای توسعه این روش تفکر است، زیرا از تار کردن تصویر خودداری میکند. از انتخاب و خواندن برنامهنویسی سیستمها با زیگ متشکریم. بیایید با هم به عمق آن برویم و تمام پتانسیل زیگ را آزاد کنیم! کدنویسی خوبی داشته باشید! این کتاب برای چه کسی مناسب است؟ این کتاب برای برنامهنویسانی است که زیگ را در سطح پایه درک میکنند و میخواهند از آن برای انجام کارهای جدی سیستمی استفاده کنند، و همچنین برنامهنویسان سیستم متوسط و باتجربه در Go، Python، Java، C، C++ یا Rust که کنجکاوند بدانند زیگ چه چیزی به این رشته اضافه میکند. نیازی نیست که متخصص زیگ باشید – آشنایی عملی با سینتکس، سیستم نوع و کتابخانه استاندارد پایه برای دنبال کردن هر فصل از ابتدا کافی است. اگر کد برنامه را به زبانهای سطح بالاتر نوشتهاید و اولین برخورد جدی خود را با برنامهنویسی سیستمها انجام میدهید، برخی از بخشها شما را به چالش میکشند. فصلهای مربوط به تخصیصدهندههای حافظه، ساختارهای داده و تجزیه پروتکل دودویی به طور خاص، تمایل به کنار آمدن با ایدههای ناآشنا را قبل از حل کامل آنها فرض میکنند. خواندن مجدد یک بخش دشوار اغلب جزئیاتی را آشکار میکند که در بار اول نامرئی بودند. این به معنای ناتوانی در درک نیست – بلکه به معنای چگونگی انباشت دانش سیستمها است. در سراسر کتاب، برنامههای کاربردی، نتایج بنچمارک و تمرینهایی را خواهید یافت که ریشه در مسائل واقعی دارند. ابزارهایی که ما میسازیم – یک زمانبند کار، یک نمایهساز فایل، یک سرور حافظه پنهان، یک مفسر – تصاویر سادهشدهای از مفاهیم نیستند. آنها مفاهیمی هستند که به صورت کدی بیان شدهاند که کامپایل و اجرا میشود. آنها را بخوانید، اجرا کنید، اصلاح کنید، بشکنید و مشاهده کنید که چه تغییراتی رخ میدهد! مطالعه غیرفعال شما را فقط تا حدی در سیستمها پیش میبرد.
Welcome to the 1st Edition of Systems Programming with Zig! Systems programming has always been a discipline defined by honesty. Honest about what the hardware can do. Honest about where the memory came from and where it goes. Honest about the cost of every abstraction. For decades, C was the language that embodied that honesty — not because it was elegant but because it hid almost nothing. You saw the pointers. You managed the memory. You felt the machine beneath your fingers. Zig carries that tradition forward but it does something C never quite managed: it makes the honest path also the convenient one. There is no hidden control flow. There is no global allocator quietly doing work on your behalf. There is no runtime making decisions you did not ask for. What you write is what runs, and the compiler will tell you — loudly, at build time — when what you wrote does not match what the machine requires. That quality, that refusal to let complexity hide in corners, is what makes Zig a genuinely interesting language for systems work rather than merely another contender. This book is for programmers who want to understand systems, not just use them. We assume you can read Zig code and navigate a UNIX terminal. What we do not assume is that you already know why a TCP echo server blocks on accept(), what the kernel I/O scheduler is doing while your buffered writer accumulates bytes or why the wrong allocator choice in a hot loop can cost you an order of magnitude in throughput. Those are the questions this book is built around. We build real tools throughout. A tee(1) clone, a Zip file lister, a file watcher backed by platformspecific kernel primitives, a concurrent job scheduler, a production-grade in-memory cache with a custom binary protocol, a note-taking service backed by SQLite3, and, finally, a working interpreter for a small programming language built from scratch. These are not toy examples dressed up as projects. They are the kind of programs that force you to make architectural decisions, feel the consequences of those decisions in the benchmark output, and understand why the systems community settled on the patterns it did. In the tradition of foundational texts such as The UNIX Programming Environment and The C Programming Language, we frequently pause to examine the why. When we introduce a mutex, we explain what goes wrong without one. When we choose an arena allocator, we benchmark the alternative. When we design a binary protocol, we show what comptime can enforce that a runtime check cannot. The code is a vehicle for understanding engineering tradeoffs, and those tradeoffs are the real curriculum. Zig 0.16.x arrived with significant changes — new I/O abstractions, a renamed allocator, a reworked networking API — and this book is written against that version throughout. Every code listing compiles and runs on Zig 0.16.0. Where the language made an interesting choice or broke with an older convention, we say so explicitly, because understanding why a language evolves is part of understanding the language. Systems programming is not a finishing school for programmers who have mastered everything else. It is a way of thinking — about resources, about time, about the gap between what you asked the machine to do and what it actually did. Zig is an exceptionally clear lens for developing that way of thinking, because it refuses to blur the picture. Thank you for choosing and reading Systems Programming with Zig. Let us dive in and unlock the full potential of Zig together! Happy coding! Soli Deo gloria Who this book is for This book is for programmers who already understand Zig at a basic level and want to use it to do serious systems work, as well as intermediate and experienced systems programmers in Go, Python, Java, C, C++ or Rust who are curious about what Zig brings to the discipline. You do not need to be a Zig expert — a working familiarity with the syntax, the type system, and the basic standard library is enough to follow every chapter from the start. If you have written application code in higher-level languages and are making your first serious contact with systems programming, some sections will challenge you. The chapters on memory allocators, data structures, and binary protocol parsing in particular assume a willingness to sit with unfamiliar ideas before they fully resolve. A second reading of a difficult section often reveals details that were invisible the first time through. That is not a failure of comprehension — it is how systems knowledge accumulates. Throughout the book, you will find working programs, benchmark results, and exercises grounded in real problems. The tools we build — a job scheduler, a file indexer, a cache server, an interpreter — are not simplified illustrations of the concepts. They are the concepts, expressed in code that compiles and runs. Read them, run them, modify them, break them, and observe what changes! Passive reading will take you only so far in systems programming. Finally, be prepared for the compiler to argue with you, for benchmarks to produce surprising numbers, and for bugs to hide in places that seem unrelated to where you made the change. This is not a sign that you are doing something wrong. It is the nature of the discipline. Systems programming is an ongoing negotiation between your intentions and the machine’s reality, and Zig is unusually honest about where the gaps are. That honesty is uncomfortable at first and invaluable thereafter.
این کتاب را میتوانید از لینک زیر بصورت رایگان دانلود کنید:
Download: Systems Programming with Zig





نظرات کاربران