Clean Code in Python: Develop maintainable and efficient code, 2nd Edition
معرفی کتاب «Clean Code in Python: Develop maintainable and efficient code, 2nd Edition» نوشتهٔ Anaya, Mariano، منتشرشده توسط نشر Packt Publishing Limited در سال 2021. این کتاب در 5 صفحه، فرمت pdf، زبان انگلیسی ارائه شده است. «Clean Code in Python: Develop maintainable and efficient code, 2nd Edition» در دستهٔ بدون دستهبندی قرار دارد.
Preface......Page 16 Who this book is for?......Page 17 What this book covers......Page 19 Download the color images......Page 21 Conventions used......Page 22 Reviews......Page 23 Introduction, Code Formatting, and Tools......Page 25 The meaning of clean code......Page 26 The importance of having clean code......Page 27 Some exceptions......Page 29 Code formatting......Page 31 Adhering to a coding style guide on your project......Page 32 Documentation......Page 35 Code comments......Page 36 Docstrings......Page 37 Annotations......Page 41 Do annotations replace docstrings?......Page 45 Tooling......Page 47 Checking type consistency......Page 48 Generic validations in code......Page 51 Automatic formatting......Page 53 Setup for automatic checks......Page 56 Summary......Page 58 References......Page 59 Pythonic Code......Page 60 Indexes and slices......Page 61 Creating your own sequences......Page 63 Context managers......Page 66 Implementing context managers......Page 69 Comprehensions and assignment expressions......Page 73 Properties, attributes, and different types of methods for objects......Page 76 Underscores in Python......Page 77 Properties......Page 80 Creating classes with a more compact syntax......Page 83 Iterable objects......Page 87 Creating iterable objects......Page 88 Creating sequences......Page 91 Container objects......Page 93 Dynamic attributes for objects......Page 95 Callable objects......Page 98 Summary of magic methods......Page 99 Caveats in Python......Page 101 Mutable default arguments......Page 102 Extending built-in types......Page 103 A brief introduction to asynchronous code......Page 106 References......Page 109 General Traits of Good Code......Page 111 Design by contract......Page 112 Preconditions......Page 114 Postconditions......Page 115 Design by contract – conclusions......Page 116 Defensive programming......Page 117 Error handling......Page 118 Value substitution......Page 119 Exception handling......Page 120 Using assertions in Python......Page 128 Separation of concerns......Page 131 Cohesion and coupling......Page 132 Acronyms to live by......Page 133 DRY/OAOO......Page 134 YAGNI......Page 136 KIS......Page 138 EAFP/LBYL......Page 140 Inheritance in Python......Page 141 When inheritance is a good decision......Page 142 Anti-patterns for inheritance......Page 143 Method Resolution Order (MRO)......Page 147 Mixins......Page 149 How function arguments work in Python......Page 151 How arguments are copied to functions......Page 152 Variable number of arguments......Page 153 Positional-only parameters......Page 159 Keyword-only arguments......Page 161 The number of arguments in functions......Page 162 Function arguments and coupling......Page 163 Compact function signatures that take too many arguments......Page 164 Orthogonality in software......Page 166 Structuring the code......Page 168 Summary......Page 170 References......Page 171 The SOLID Principles......Page 173 The single responsibility principle......Page 174 A class with too many responsibilities......Page 175 Distributing responsibilities......Page 176 The open/closed principle......Page 178 Example of maintainability perils for not following the OCP......Page 179 Refactoring the events system for extensibility......Page 182 Extending the events system......Page 184 Liskov's substitution principle......Page 186 Using mypy to detect incorrect method signatures......Page 188 Detecting incompatible signatures with pylint......Page 190 More subtle cases of LSP violations......Page 191 Remarks on the LSP......Page 194 Interface segregation......Page 195 The smaller the interface, the better......Page 197 How small should an interface be?......Page 199 Dependency inversion......Page 200 A case of rigid dependencies......Page 201 Inverting the dependencies......Page 202 Dependency injection......Page 203 Summary......Page 206 References......Page 208 Using Decorators to Improve Our Code......Page 209 What are decorators in Python?......Page 210 Function decorators......Page 211 Decorators for classes......Page 213 Other types of decorator......Page 217 Passing arguments to decorators......Page 218 Decorators with nested functions......Page 219 Decorator objects......Page 221 Decorators with default values......Page 223 Decorators for coroutines......Page 226 Extended syntax for decorators......Page 229 Good uses for decorators......Page 230 Adapting function signatures......Page 231 Tracing code......Page 233 Preserving data about the original wrapped object......Page 234 Incorrect handling of side effects in a decorator......Page 237 Requiring decorators with side effects......Page 240 Creating decorators that will always work......Page 242 Decorators and clean code......Page 245 Composition over inheritance......Page 246 The DRY principle with decorators......Page 249 Decorators and separation of concerns......Page 251 Analysis of good decorators......Page 253 Summary......Page 254 References......Page 255 A first look at descriptors......Page 257 The machinery behind descriptors......Page 258 The get method......Page 262 The set method......Page 264 The delete method......Page 266 The set name method......Page 269 Non-data descriptors......Page 271 Data descriptors......Page 274 An application of descriptors......Page 277 A first attempt without using descriptors......Page 278 The idiomatic implementation......Page 279 Different forms of implementing descriptors......Page 282 The issue of shared state......Page 283 Accessing the dictionary of the object......Page 284 Using weak references......Page 285 Reusing code......Page 286 An alternative to class decorators......Page 287 Analysis of descriptors......Page 291 Functions and methods......Page 292 Built-in decorators for methods......Page 296 Slots......Page 298 Implementing descriptors in decorators......Page 299 Interface of descriptors......Page 300 Object-oriented design of the descriptors......Page 301 Summary......Page 302 References......Page 303 Generators, Iterators, and Asynchronous Programming......Page 305 Creating generators......Page 306 A first look at generators......Page 307 Generator expressions......Page 310 Idioms for iteration......Page 312 The next() function......Page 315 Using a generator......Page 316 Itertools......Page 317 Simplifying code through iterators......Page 318 The iterator pattern in Python......Page 321 Coroutines......Page 326 close()......Page 327 throw(ex_type[, ex_value[, ex_traceback]])......Page 328 send(value)......Page 330 Returning values in coroutines......Page 334 Delegating into smaller coroutines – the 'yield from' syntax......Page 336 Asynchronous programming......Page 342 Magic asynchronous methods......Page 345 Asynchronous context managers......Page 346 Other magic methods......Page 347 Asynchronous iteration......Page 348 Asynchronous generators......Page 351 References......Page 353 Unit Testing and Refactoring......Page 355 Design principles and unit testing......Page 356 A note about other forms of automated testing......Page 357 Unit testing and agile software development......Page 359 Unit testing and software design......Page 360 Defining the boundaries of what to test......Page 364 Frameworks and libraries for unit testing......Page 365 unittest......Page 367 pytest......Page 373 Code coverage......Page 378 Mock objects......Page 382 Refactoring......Page 389 Evolving our code......Page 390 Production code isn't the only one that evolves......Page 392 More about testing......Page 394 Mutation testing......Page 395 Boundaries or limit values......Page 398 Classes of equivalence......Page 399 Edge cases......Page 400 A brief introduction to test-driven development......Page 401 Summary......Page 402 References......Page 403 Common Design Patterns......Page 404 Design pattern considerations in Python......Page 405 Design patterns in action......Page 406 Singleton and shared state (monostate)......Page 408 Adapter......Page 415 Composite......Page 418 Decorator......Page 419 Facade......Page 422 Chain of responsibility......Page 424 The template method......Page 427 Command......Page 428 State......Page 430 The null object pattern......Page 435 Final thoughts about design patterns......Page 438 The influence of patterns over the design......Page 439 Design patterns as theory......Page 440 Names in our models......Page 441 References......Page 442 From clean code to clean architecture......Page 444 Separation of concerns......Page 446 Monolithic applications and microservices......Page 447 Abstractions......Page 449 Software components......Page 450 Packages......Page 451 Managing dependencies......Page 455 Other considerations when managing dependencies......Page 457 Artifact versions......Page 459 Docker containers......Page 460 Use case......Page 462 Domain models......Page 463 Calling from the application......Page 465 Adapters......Page 467 The services......Page 468 Analysis......Page 471 Limitations......Page 472 Testability......Page 473 Summary......Page 474 References......Page 475 Summing it all up......Page 476 Other Books You May Enjoy......Page 478 Index......Page 480 Improve your software engineering practices to tackle inefficiencies, errors, and other perils that emerge due to bad code Key Features Enhance your coding skills to increase efficiency as well as reflect the new features introduced in Python 3.9 Understand how to apply microservices to your legacy systems by implementing practical techniques Learn to implement the refactoring techniques and SOLID principles in Python Book Description The Python language is immensely prevalent in numerous areas, such as software construction, systems administration, and data processing. Experienced professionals in every field face the challenges of disorganization, poor readability, and low testability as a result of unstructured code. With updated code and revised content aligned to the new features of Python 3.9, this second edition of Clean Code in Python will provide you with all the tools you need to overcome these obstacles and manage your projects successfully. The book begins by describing the basic elements of writing clean code and how it plays a key role in Python programming. You will learn about writing efficient and readable code using the Python standard library and best practices for software design. The book delves deeply into object-oriented programming in Python and shows you how to use objects with descriptors and generators. It will also show you the design principles of software testing and how to resolve problems by implementing software design patterns in your code. In the final chapter, we break down a monolithic application into a microservices based one starting from the code as the basis for a solid platform. By the end of this clean code book, you will be proficient in applying industry-approved coding practices to design clean, sustainable, and readable real-world Python code. What you will learn Set up a productive development environment by leveraging automatic tools Leverage the magic methods in Python to write better code, abstracting complexity away and encapsulating details Create advanced object-oriented designs using unique features of Python, such as descriptors Eliminate duplicated code by creating powerful abstractions using software engineering principles of object-oriented design Create Python-specific solutions using decorators and descriptors Refactor code effectively with the help of unit tests Build the foundations for solid architecture with a clean code base as its cornerstone Who this book is for This book wil..
دانلود کتاب Clean Code in Python: Develop maintainable and efficient code, 2nd Edition