Summary
Professional developers know the many benefits of writing application code that’s clean, well-organized, and easy to maintain. By learning and following established patterns and best practices, you can take your code and your career to a new level.
With Practices of the Python Pro, you’ll learn to design professional-level, clean, easily maintainable software at scale using the incredibly popular programming language, Python. You’ll find easy-to-grok examples that use pseudocode and Python to introduce software development best practices, along with dozens of instantly useful techniques that will help you code like a pro.
Purchase of the print book includes a free eBook in PDF, Kindle, and ePub formats from Manning Publications.
About the technology
Professional-quality code does more than just run without bugs. It’s clean, readable, and easy to maintain. To step up from a capable Python coder to a professional developer, you need to learn industry standards for coding style, application design, and development process. That’s where this book is indispensable.
About the book
Practices of the Python Pro teaches you to design and write professional-quality software that’s understandable, maintainable, and extensible. Dane Hillard is a Python pro who has helped many dozens of developers make this step, and he knows what it takes. With helpful examples and exercises, he teaches you when, why, and how to modularize your code, how to improve quality by reducing complexity, and much more. Embrace these core principles, and your code will become easier for you and others to read, maintain, and reuse.
What's inside
- Organizing large Python projects
- Achieving the right levels of abstraction
- Writing clean, reusable code Inheritance and composition
- Considerations for testing and performance
About the reader
For readers familiar with the basics of Python, or another OO language.
About the author
Dane Hillard has spent the majority of his development career using Python to build web applications.
Table of Contents:
PART 1 WHY IT ALL MATTERS
1 ¦ The bigger picture
PART 2 FOUNDATIONS OF DESIGN
2 ¦ Separation of concerns
3 ¦ Abstraction and encapsulation
4 ¦ Designing for high performance
5 ¦ Testing your software
PART 3 NAILING DOWN LARGE SYSTEMS
6 ¦ Separation of concerns in practice
7 ¦ Extensibility and flexibility
8 ¦ The rules (and exceptions) of inheritance
9 ¦ Keeping things lightweight
10 ¦ Achieving loose coupling
PART 4 WHAT’S NEXT?
11 ¦ Onward and upward
Author(s): Dane Hillard
Edition: 1
Publisher: Manning
Year: 2020
Language: English
Pages: 248
Practices of the Python Pro
brief contents
contents
preface
acknowledgments
about this book
Who should read this book
How this book is organized: A roadmap
About the code
liveBook discussion forum
about the author
about the cover illustration
Part 1: Why it all matters
Chapter 1: The bigger picture
1.1 Python is an enterprise language
1.1.1 The times they are a-changin’
1.1.2 What I like about Python
1.2 Python is a teaching language
1.3 Design is a process
1.3.1 The user experience
1.3.2 You’ve been here before
1.4 Design enables better software
1.4.1 Considerations in software design
1.4.2 Organically grown software
1.5 When to invest in design
1.6 New beginnings
1.7 Design is democratic
1.7.1 Presence of mind
1.8 How to use this book
Part 2: Foundations of design
Chapter 2: Separation of concerns
2.1 Namespacing
2.1.1 Namespaces and the import statement
2.1.2 The many masks of importing
2.1.3 Namespaces prevent collisions
2.2 The hierarchy of separation in Python
2.2.1 Functions
2.2.2 Classes
2.2.3 Modules
2.2.4 Packages
Chapter 3: Abstraction and encapsulation
3.1 What is abstraction?
3.1.1 The “black box”
3.1.2 Abstraction is like an onion
3.1.3 Abstraction is a simplifier
3.1.4 Decomposition enables abstraction
3.2 Encapsulation
3.2.1 Encapsulation constructs in Python
3.2.2 Expectations of privacy in Python
3.3 Try it out
3.3.1 Refactoring
3.4 Programming styles are an abstraction too
3.4.1 Procedural programming
3.4.2 Functional programming
3.4.3 Declarative programming
3.5 Typing, inheritance, and polymorphism
3.6 Recognizing the wrong abstraction
3.6.1 Square pegs in round holes
3.6.2 Clever gets the cleaver
Chapter 4: Designing for high performance
4.1 Hurtling through time and space
4.1.1 Complexity is a little . . . complex
4.1.2 Time complexity
4.1.3 Space complexity
4.2 Performance and data types
4.2.1 Data types for constant time
4.2.2 Data types for linear time
4.2.3 Space complexity of operations on data types
4.3 Make it work, make it right, make it fast
4.3.1 Making it work
4.3.2 Making it right
4.3.3 Making it fast
4.4 Tools
4.4.1 timeit
4.4.2 CPU profiling
4.5 Try it out
Chapter 5: Testing your software
5.1 What is software testing?
5.1.1 Does it do what it says on the tin?
5.1.2 The anatomy of a functional test
5.2 Functional testing approaches
5.2.1 Manual testing
5.2.2 Automated testing
5.2.3 Acceptance testing
5.2.4 Unit testing
5.2.5 Integration testing
5.2.6 The testing pyramid
5.2.7 Regression testing
5.3 Statements of fact
5.4 Unit testing with unittest
5.4.1 Test organization with unittest
5.4.2 Running tests with unittest
5.4.3 Writing your first test with unittest
5.4.4 Writing your first integration test with unittest
5.4.5 Test doubles
5.4.6 Try it out
5.4.7 Writing interesting tests
5.5 Testing with pytest
5.5.1 Test organization with pytest
5.5.2 Converting unittest tests to pytest
5.6 Beyond functional testing
5.6.1 Performance testing
5.6.2 Load testing
5.7 Test-driven development: A primer
5.7.1 It’s a mindset
5.7.2 It’s a philosophy
Part 3: Nailing down large systems
Chapter 6: Separation of concerns in practice
6.1 A command-line bookmarking application
6.2 A tour of Bark
6.2.1 The benefits of separation: Reprise
6.3 An initial code structure, by concern
6.3.1 The persistence layer
6.3.2 The business logic layer
6.3.3 The presentation layer
Chapter 7: Extensibility and f lexibility
7.1 What is extensible code?
7.1.1 Adding new behaviors
7.1.2 Modifying existing behaviors
7.1.3 Loose coupling
7.2 Solutions for rigidity
7.2.1 Letting go: Inversion of control
7.2.2 The devil’s in the details: Relying on interfaces
7.2.3 Fighting entropy: The robustness principle
7.3 An exercise in extension
Chapter 8: The rules (and exceptions) of inheritance
8.1 The inheritance of programming past
8.1.1 The silver bullet
8.1.2 The challenges of hierarchies
8.2 The inheritance of programming present
8.2.1 What is inheritance for, really?
8.2.2 Substitutability
8.2.3 The ideal use case for inheritance
8.3 Inheritance in Python
8.3.1 Type inspection
8.3.2 Superclass access
8.3.3 Multiple inheritance and method resolution order
8.3.4 Abstract base classes
8.4 Inheritance and composition in Bark
8.4.1 Refactoring to use an abstract base class
8.4.2 A final check on your inheritance work
Chapter 9: Keeping things lightweight
9.1 How big should my class/function/module be?
9.1.1 Physical size
9.1.2 Single responsibility
9.1.3 Code complexity
9.2 Breaking down complexity
9.2.1 Extracting configuration
9.2.2 Extracting functions
9.3 Decomposing classes
9.3.1 Initialization complexity
9.3.2 Extracting classes and forwarding calls
Chapter 10: Achieving loose coupling
10.1 Defining coupling
10.1.1 The connective tissue
10.1.2 Tight coupling
10.1.3 Loose coupling
10.2 Recognizing coupling
10.2.1 Feature envy
10.2.2 Shotgun surgery
10.2.3 Leaky abstractions
10.3 Coupling in Bark
10.4 Addressing coupling
10.4.1 User messaging
10.4.2 Bookmark persistence
10.4.3 Try it out
Part 4: What’s next?
Chapter 11: Onward and upward
11.1 What now?
11.1.1 Develop a plan
11.1.2 Execute the plan
11.1.3 Track your progress
11.2 Design patterns
11.2.1 Ups and downs of design patterns in Python
11.2.2 Terms to start with
11.3 Distributed systems
11.3.1 Modes of failure in distributed systems
11.3.2 Addressing application state
11.3.3 Terms to start with
11.4 Take a Python deep dive
11.4.1 Python code style
11.4.2 Language features are patterns
11.4.3 Terms to start with
11.5 Where you’ve been
11.5.1 There and back again: A developer’s tale
11.5.2 Signing off
Appendix: Installing Python
A.1 What version of Python should I use?
A.2 The “system” Python
A.3 Installing other versions of Python
A.3.1 Download the official Python
A.3.2 Download using Anaconda
A.4 Verifying the installation
index
A
B
C
D
E
F
G
H
I
K
L
M
N
O
P
Q
R
S
T
U
V
W
Y
Z