Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Clean Code in Python

You're reading from   Clean Code in Python Refactor your legacy code base

Arrow left icon
Product type Paperback
Published in Aug 2018
Publisher Packt
ISBN-13 9781788835831
Length 332 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Mariano Anaya Mariano Anaya
Author Profile Icon Mariano Anaya
Mariano Anaya
Arrow right icon
View More author details
Toc

Table of Contents (12) Chapters Close

Preface 1. Introduction, Code Formatting, and Tools FREE CHAPTER 2. Pythonic Code 3. General Traits of Good Code 4. The SOLID Principles 5. Using Decorators to Improve Our Code 6. Getting More Out of Our Objects with Descriptors 7. Using Generators 8. Unit Testing and Refactoring 9. Common Design Patterns 10. Clean Architecture 11. Other Books You May Enjoy

What this book covers

Chapter 1, Introduction, Code Formatting, and Tools, is an introduction to the main tools you need to set up a development environment in Python. We cover the basics a Python developer is recommended to know to start working with the language, as well as some guidelines for maintaining readable code in the project, such as tools for static analysis, documentation, type checking, and code formatting.

Chapter 2, Pythonic Code, looks at the first idioms in Python, which we will continue to use in the following chapters. We cover the particular features of Python, how they should be used, and we start building knowledge around the idea that Pythonic code is in general much better quality code.

Chapter 3, General Traits of Good Code, reviews general principles of software engineering that focus on writing maintainable code. We explore the idea and apply the concepts with the tools in the language.

Chapter 4, The SOLID Principles, covers a set of design principles for object-oriented software design. This acronym is part of the language or jargon of software engineering, and we see how each one of them can be applied to Python. Arguably not all of them are entirely applicable due to the nature of the language.

Chapter 5, Using Decorators to Improve Our Code, looks at one of the greatest features of Python. After understanding how to create decorators (for functions and classes), we put them in action for reusing code, separating responsibilities, and creating more granular functions.

Chapter 6, Getting More Out of Our Objects with Descriptors, explores descriptors in Python, which take object-oriented design to a new level. While this is a feature more related to frameworks and tools, we can see how to improve the readability of our code with descriptors, and also reuse code.

Chapter 7, Using Generators, shows that generators are probably the best feature of Python. The fact that iteration is a core component of Python could make us think that it leads to a new programming paradigm. By using generators and iterators in general, we can think about the way we write our programs. With the lessons learned from generators, we go further and learn about coroutines in Python, and the basics of asynchronous programming.

Chapter 8, Unit Testing and Refactoring, discusses the importance of unit tests in any code base that claims to be maintainable. The chapter reviews the importance of unit tests, and we explore the main frameworks for this (unittest and pytest).

Chapter 9, Common Design Patterns, reviews how to implement the most common design patterns in Python, not from the point of view of solving a problem, but by examining how they solve problems by leveraging a better and more maintainable solution. The chapter mentions the peculiarities of Python that have made some of the design patterns invisible and takes a pragmatic approach to implement some of them.

Chapter 10, Clean Architecture, focuses on the idea that clean code is the base of a good architecture. All those details we mentioned in the first chapter, and everything else revisited along the way, will play a critical role in the entire design when the system is deployed.

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime