没有合适的资源?快使用搜索试试~ 我知道了~
首页Python编程中的《CleanCode》:软件工程原则实践指南
Python编程中的《CleanCode》:软件工程原则实践指南
![](https://csdnimg.cn/release/wenkucmsfe/public/img/star.98a08eaa.png)
"《Clean Code in Python》是一本专为软件工程原则在Python编程实践中的应用而撰写的书籍。它旨在填补当前市场上关于软件工程理论和Python技术之间知识的空白,特别关注如何对遗留代码库进行重构,以提高代码质量与可维护性。作者Mariano Anaya以BIRMINGHAM-MUMBAI为背景,通过这本书探讨了如何遵循专业的编程规范和最佳实践,以创建出高效、清晰且易于理解的Python代码。 该书版权由Packt Publishing持有,并强调所有内容未经许可不得复制或传播,除非用于学术引用。尽管作者和出版社已经尽力确保信息的准确性,但书中提供的信息不承担任何形式的保证,无论是明示的还是暗示的。用户在使用本书内容时应自行判断其适用性和风险。 《Clean Code in Python》的出版过程由多位专业编辑参与,包括Merint Mathew作为委托编辑,Denim Pinto负责项目收购,以及Priyanka Sawant担任内容开发编辑。这些人员的协作确保了书籍不仅内容丰富,而且符合行业标准,为读者提供了一套系统的方法来提升Python代码的清晰度和可读性,帮助开发者在实际项目中实施和应用软件工程的最佳实践。无论是初次接触Python的开发者,还是希望优化现有代码库的专业人士,这本书都是一个重要的学习资源和参考指南。"
资源详情
资源推荐
![](https://csdnimg.cn/release/download_crawler_static/10747130/bg10.jpg)
Preface
[ 3 ]
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.
![](https://csdnimg.cn/release/download_crawler_static/10747130/bg11.jpg)
Preface
[ 4 ]
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.
To get the most out of this book
The reader should be familiarized with Python's syntax and have a valid Python interpreter
installed, which can be downloaded from https://www.python.org/downloads/
It is recommended to follow the examples in the book and test the code locally. For this, it is
highly recommended to create a virtual environment with Python 3.7 and run the code
with this interpreter. Instructions to create a virtual environment can be found at https://
docs.python.org/3/tutorial/venv.html.
Download the example code files
You can download the example code files for this book from your account at
www.packtpub.com. If you purchased this book elsewhere, you can visit
www.packtpub.com/support and register to have the files emailed directly to you.
You can download the code files by following these steps:
Log in or register at www.packtpub.com.1.
Select the SUPPORT tab.2.
Click on Code Downloads & Errata.3.
Enter the name of the book in the Search box and follow the onscreen4.
instructions.
![](https://csdnimg.cn/release/download_crawler_static/10747130/bg12.jpg)
Preface
[ 5 ]
Once the file is downloaded, please make sure that you unzip or extract the folder using the
latest version of:
WinRAR/7-Zip for Windows
Zipeg/iZip/UnRarX for Mac
7-Zip/PeaZip for Linux
The code bundle for the book is also hosted on GitHub at
https://github.com/PacktPublishing/Clean-Code-in-Python. In case there's an update
to the code, it will be updated on the existing GitHub repository.
We also have other code bundles from our rich catalog of books and videos available
at https://github.com/PacktPublishing/. Check them out!
Conventions used
There are a number of text conventions used throughout this book.
CodeInText: Indicates code words in text, database table names, folder names, filenames,
file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an
example: "Then, just running the pylint command is enough to check it in the code."
A block of code is set as follows:
class Point:
def __init__(self, lat, long):
self.lat = lat
self.long = long
When we wish to draw your attention to a particular part of a code block, the relevant lines
or items are set in bold:
setup(
name="apptool",
description="Description of the intention of the package",
long_description=long_description,
Any command-line input or output is written as follows:
>>> locate.__annotations__
{'latitude': float, 'longitue': float, 'return': __main__.Point}
Bold: Indicates a new term, an important word, or words that you see onscreen. For
example, words in menus or dialog boxes appear in the text like this. Here is an example:
"Select System info from the Administration panel."
![](https://csdnimg.cn/release/download_crawler_static/10747130/bg13.jpg)
Preface
[ 6 ]
Warnings or important notes appear like this.
Tips and tricks appear like this.
Get in touch
Feedback from our readers is always welcome.
General feedback: Email feedback@packtpub.com and mention the book title in the
subject of your message. If you have questions about any aspect of this book, please email
us at questions@packtpub.com.
Errata: Although we have taken every care to ensure the accuracy of our content, mistakes
do happen. If you have found a mistake in this book, we would be grateful if you would
report this to us. Please visit www.packtpub.com/submit-errata, selecting your book,
clicking on the Errata Submission Form link, and entering the details.
Piracy: If you come across any illegal copies of our works in any form on the Internet, we
would be grateful if you would provide us with the location address or website name.
Please contact us at copyright@packtpub.com with a link to the material.
If you are interested in becoming an author: If there is a topic that you have expertise in
and you are interested in either writing or contributing to a book, please visit
authors.packtpub.com.
Reviews
Please leave a review. Once you have read and used this book, why not leave a review on
the site that you purchased it from? Potential readers can then see and use your unbiased
opinion to make purchase decisions, we at Packt can understand what you think about our
products, and our authors can see your feedback on their book. Thank you!
For more information about Packt, please visit packtpub.com.
![](https://csdnimg.cn/release/download_crawler_static/10747130/bg14.jpg)
1
Introduction, Code Formatting,
and Tools
In this chapter, we will explore the first concepts related to clean code, starting with what it
is and what it means. The main point of the chapter is to understand that clean code is not
just a nice thing to have or a luxury in software projects. It's a necessity. Without quality
code, the project will face the perils of failing due to an accumulated technical debt.
Along the same lines, but going into a bit more detail, are the concepts of formatting and
documenting the code. This also might sound like a superfluous requirement or task, but
again, we will discover that it plays a fundamental role in keeping the code base
maintainable and workable.
We will analyze the importance of adopting a good coding guideline for this project.
Realizing that maintaining the code align to the reference is a continuous task, and we will
see how we can get help from automated tools that will ease our work. For this reason, we
quickly discuss how to configure the main tools so that they automatically run on the
project as part of the build.
After reading this chapter, you will have an idea of what clean code is, why it is important,
why formatting and documenting the code are crucial tasks, and how to automate this
process. From this, you should acquire the mindset for quickly organizing the structure of a
new project, aiming for good code quality.
After reading this chapter, you will have learned the following:
That clean code really means something far more important than formatting in
software construction
That even so, having a standard formatting is a key component to have in a
software project, for the sake of its maintainability
剩余327页未读,继续阅读
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://profile-avatar.csdnimg.cn/9c0e5fffca1a4297ad349159c6840082_tigershin.jpg!1)
tigershin
- 粉丝: 6
- 资源: 6
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![](https://csdnimg.cn/release/wenkucmsfe/public/img/voice.245cc511.png)
最新资源
- 岩石滑动与断层冲击地压:声发射特征分析
- 新时代煤炭工业八大战略新取向剖析
- 开采强度对华亭矿区冲击地压危险性的影响分析
- 新安煤矿探采对比:影响安全生产的关键因素与技术支撑
- 210MW循环流化床锅炉引风机变频改造优化与节能效果
- 浅埋煤层开采沉陷预测:方法应用与影响分析
- 优化巷道过陷落柱支护方案:数值模拟与现场试验
- 坚硬顶板定向断裂爆破技术:安全高效采煤新方案
- 北航2019算法课作业解析:投资策略与凸子多边形优化
- 断层破碎带垮冒下堆积体边界抗力分布关键影响因素
- 哈拉沟选煤厂优化末煤系统提高效率与处理能力
- 瓦斯涌出影响下采动煤体蠕变失稳研究
- 提升煤矿装载效率的可控箕斗定量装载设备设计
- 水分调控下烟煤瓦斯吸附特性对比研究
- 重介质悬浮液密度控制硬件设计与选型探讨
- 坚硬顶板巷道支护参数设计:现场测试与数值分析
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
![](https://img-home.csdnimg.cn/images/20220527035711.png)
![](https://img-home.csdnimg.cn/images/20220527035711.png)
![](https://img-home.csdnimg.cn/images/20220527035111.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![](https://csdnimg.cn/release/wenkucmsfe/public/img/green-success.6a4acb44.png)