
#Python
#Robust
#bloat
#enum
#debug
🐍 آیا پروژههای Python شما روزبهروز بزرگتر میشوند؟ آیا با افزایش اندازه کد و سختتر شدن دیباگ و نگهداری، دچار مشکل شدهاید؟ Python زبانی ساده برای یادگیری و استفاده است، اما همین سادگی میتواند باعث شود سیستمها سریعتر از حد تصور رشد کنند. خوشبختانه، Python ویژگیهایی دارد که به توسعهدهندگان کمک میکند مشکلات نگهداری را مدیریت کنند.
🛠️ در این کتاب عملی، Patrick Viafore به شما نشان میدهد چگونه از سیستم نوع (Type System) Python حداکثر استفاده را ببرید. شما با انواع تعریفشده توسط کاربر، مانند کلاسها و Enumها، و سیستم Type Hinting آشنا میشوید. همچنین یاد میگیرید چگونه Python را گسترشپذیر کنید و از یک استراتژی تست جامع به عنوان شبکه ایمنی بهره ببرید تا کد شما شفافتر و قابل نگهداریتر شود.
🎯 در این کتاب خواهید آموخت:
📖 فهرست مطالب
فصل ۱: مقدمهای بر Python مقاوم
💻 بخش اول: حاشیهنویسی کد با انواع
فصل ۲: معرفی انواع Python
فصل ۳: حاشیهنویسی انواع
فصل ۴: محدودسازی انواع
فصل ۵: انواع مجموعهها
فصل ۶: شخصیسازی Typechecker
فصل ۷: استفاده عملی از Typechecking
💻 بخش دوم: تعریف انواع خود
فصل ۸: انواع تعریفشده توسط کاربر: Enumها
فصل ۹: انواع تعریفشده توسط کاربر: Data Classes
فصل ۱۰: انواع تعریفشده توسط کاربر: کلاسها
فصل ۱۱: تعریف اینترفیسها
فصل ۱۲: Subtyping
فصل ۱۳: Protocolها
فصل ۱۴: بررسی در زمان اجرا با Pydantic
💻 بخش سوم: Python قابل گسترش
فصل ۱۵: گسترشپذیری
فصل ۱۶: وابستگیها
فصل ۱۷: Composability
فصل ۱۸: معماری مبتنی بر رویداد
فصل ۱۹: Python پلاگینپذیر
💻 بخش چهارم: ایجاد شبکه ایمنی
فصل ۲۰: تحلیل ایستا (Static Analysis)
فصل ۲۱: استراتژی تست
فصل ۲۲: تست پذیرش
فصل ۲۳: تست مبتنی بر Property
فصل ۲۴: تست Mutation
👨💻 درباره کتاب
Python زبان فوقالعادهای است، اما گاهی ساخت پروژههای آیندهدار چالشبرانگیز است. این کتاب به شما نشان میدهد چگونه کد Python خود را پاک، مقاوم و قابل نگهداری کنید.
🎯 مخاطبان ایدهآل:
👨💻 درباره نویسنده
Patrick Viafore بیش از ۱۳ سال در صنعت نرمافزار فعالیت کرده و روی سیستمهای حیاتی از جمله تشخیص رعد و برق، مخابرات و سیستمهای عامل کار کرده است. او همچنین سازماندهنده HSV.py Meetup است و هدفش نزدیکتر کردن مباحث علوم کامپیوتر و مهندسی نرمافزار به جامعه توسعهدهندگان است. هماکنون در Cloud Software Group مشغول به کار است و همچنین از طریق شرکت شخصیاش، Kudzera, LLC، مشاوره و قرارداد نرمافزاری ارائه میدهد.
Does it seem like your Python projects are getting bigger and bigger? Are you feeling the pain as your codebase expands and gets tougher to debug and maintain? Python is an easy language to learn and use, but that also means systems can quickly grow beyond comprehension. Thankfully, Python has features to help developers overcome maintainability woes.
In this practical book, author Patrick Viafore shows you how to use Python's type system to the max. You'll look at user-defined types, such as classes and enums, and Python's type hinting system. You'll also learn how to make Python extensible and how to use a comprehensive testing strategy as a safety net. With these tips and techniques, you'll write clearer and more maintainable code.
Table of Contents
Chapter 1. Introduction to Robust Python
Part I. Annotating Your Code with Types
Chapter 2. Introduction to Python Types
Chapter 3. Type Annotations
Chapter 4. Constraining Types
Chapter 5. Collection Types
Chapter 6. Customizing Your Typechecker
Chapter 7. Adopting Typechecking Practically
Part II. Defining Your Own Types
Chapter 8. User-Defined Types: Enums
Chapter 9. User-Defined Types: Data Classes
Chapter 10. User-Defined Types: Classes
Chapter 11. Defining Your Interfaces
Chapter 12. Subtyping
Chapter 13. Protocols
Chapter 14. Runtime Checking With Pydantic
Part III. Extensible Python
Chapter 15. Extensibility
Chapter 16. Dependencies
Chapter 17. Composability
Chapter 18. Event-Driven Architecture
Chapter 19. Pluggable Python
Part IV. Building a Safety Net
Chapter 20. Static Analysis
Chapter 21. Testing Strategy
Chapter 22. Acceptance Testing
Chapter 23. Property-Based Testing
Chapter 24. Mutation Testing
About This Book
Python is a wonderful language, but it occasionally makes building for the future tricky. Some proponents of other programming languages have decried Python as “not production-grade” or “useful for prototyping only,” but the truth is that many developers only scratch the surface, rather than learning all the tools and tricks for writing robust Python. Throughout this book, you’ll learn how to do better. You’ll journey through numerous ways to make Python clean and maintainable. Your future maintainers will enjoy working with your code, as it was designed up front to make things easy. So go, read this book, look toward the future, and build awesome software that will last.
Ideal readers include:
Who Should Read This Book
This book is for any Python developer who is looking to grow the code they work on in a sustainable and maintainable fashion. This is not intended to be your first Python text; I expect that you have written Python before. You should be comfortable with Python control flow, and have worked with classes before. If you are looking for a more introductory text, I suggest reading Learning Python by Mark Lutz (O’Reilly) first.
While I will be covering many advanced Python topics, the goal of this book is not to be a how-to for using all of Python’s features. Instead, the features are a backdrop for a larger conversation about robustness and how your choices impact maintainability. At times I will discuss strategies that you should rarely use, if at all. That is because I want to illustrate first principles of robustness; the journey of understanding why and how we make decisions in code is more important than knowing what tools to use in an optimal scenario. In practice, the optimal scenario is a rare occurence. Use the principles in this book to draw your own conclusions from your codebase.
This book is not a reference book. You might call it a discussion book. Each chapter should be a starting point for developers in your organization to discuss, together, how best to apply these principles. Start a book club, discussion group, or lunch and learn to foster communication. I have proposed discussion topics in each chapter to get the converstation started. When you come across these topics, I encourage you to stop and reflect on your current codebase. Talk among your peers and use these topics as a springboard for discussing the state of your code, processes, and workflows. If you are interested in a reference book about the Python language, I heartily recommend Fluent Python by Luciano Ramalho (O’Reilly; a second edition is forthcoming in late 2021).
A system can be robust in many different ways. It can be security hardened, scalable, fault-tolerant, or less likely to introduce new errors. Each one of these facets of robustness warrants a full book; this book is focused on preventing the developers who inherit your code from creating new faults in your system. I will show you how to communicate to future developers, how to make their lives easier through architectural patterns, and how to catch errors in your codebase before they make it into production. This book zeroes in on the robustness of your Python codebase, not the robustness of your system as a whole.
I will be covering a wealth of information, from many different areas of software, including software engineering, computer science, testing, functional programming, and object-oriented programming (OOP). I do not expect you to have a background in these fields. There are sections where I explain things at a beginner level; this is often to deconstruct how we think about core fundamentals of the language. This is, for the most part, an intermediate-level text.
This book focuses on writing software over time. If a lot of your code is a prototype, throwaway, or disposable in any other fashion, the advice in this book will end up creating more work than is necessary for your project. Likewise if your project is small—say, under one hundred lines of Python. Making code maintainable does add complexity; there’s no doubt about that. However, I’ll guide you through minimizing that complexity. If your code lives longer than a few weeks or grows to a considerable size, you need to consider the sustainability of your codebase.
About the Author
Patrick Viafore has been working in the software industry for 13+ years, working on mission critical software systems, including in lightning detection, telecommunications and operating systems. His work in static typed languages has influenced his approach to dynamic languages and how we can make them safer and more robust. He also is an organizer of the HSV.py meetup, where he can observe common Python obstacles, from beginners to experts. His goal is to make computer science/software engineering topics more approachable to the developer community.
Patrick currently works at Cloud Software Group, working on desktop and application virtualization. He also does software consulting and contracting through his business, Kudzera, LLC.









