Skip to product information
Clean Code Now in Python
Clean Code Now in Python
Description
Book Introduction
Do you want Python code that's highly readable, maintainable, and easy to extend? Now that you've mastered basic Python programming syntax and tutorials, what's the next step to becoming a competent and confident software developer? This book contains the delightful experiences and honest know-how of a seasoned programmer, all of the practical programming knowledge you can apply in your field. A comprehensive compilation of practical programming knowledge for the growth and advancement of Python developers!
  • You can preview some of the book's contents.
    Preview

index
[Part 1] Preparation
Chapter 1: Understanding Error Messages and Asking Questions to Get Help from Experts
__How to read Python error messages
____Tracking Information Investigation
____Find error messages
Error prevention using __linters
__How to ask for programming advice
____Let's reduce unnecessary communication by providing sufficient information in advance.
____Let's write sentences in the form of questions with question marks.
____Find the appropriate website and ask a question
____Let's give a title that summarizes the question
____Describe what you want to do with the code.
____Please provide the full error message
____Let's share the entire code
____Make your code easier to read with appropriate formatting
____Let people know what you tried
____Share your settings
__Examples of good questions
__organize

Chapter 2: Setting Up the Environment and Using the Command Line
__file system
____Python's path
____Home Directory
____Current working directory
____Absolute path vs. relative path
__programs and processes
__command line
____Open a terminal window
____How to run a program from the command line
____command line arguments
____How to run Python code with the -c option from the command line
____Running a Python program from the command line
Run the ____py.exe program
____Executing commands in a Python program
Tab completion to minimize ____typing
View ____command history
____Collection of essential commands
__Environment variables and PATH
View ____environment variables
Working with the ____PATH environment variable
____Changing the PATH environment variable on the command line
Permanently add the ____ folder to your PATH: Windows environment
Permanently adding the ____ folder to your PATH: macOS and Linux environments
__How to run a Python program without using the command line
____Windows environment
____macOS environment
____Ubuntu Linux environment
__organize

[Part 2] Best Practices, Tools, and Techniques for Clean Code
Chapter 3: Establishing Coding Style and Automating Code Formatting
__Why You Lose Trust from Your Colleagues or Collaborators
__Style Guide and PEP 8
__horizontal spacing
____Use space characters for indentation
____Using spaces within code lines
__vertical spacing
____Examples of using vertical spacing
____Vertical Spacing Best Practices
__Strict code formatter, Black
____How to install Black Tools
____How to run Black from the command line
____Disable blacking for specific parts of code
__organize

Chapter 4: Easy-to-understand names
__Case notation
__PEP 8 Naming Conventions
__Appropriate length of name
____Too short name
____Too long name
__Create a searchable name
__Avoid jokes, puns, and cultural references
__Do not overwrite built-in names
__The worst variable name ever
__organize

Chapter 5: Detecting and Responding to Code Smells
__Duplicate code
__Magic Number
__Commented code and dead code
__Debugging output
Variables with a numeric suffix
__A class that should just be a function or module
__Nested list comprehensions
__Empty exception handling blocks and poor error messages
__Myths about code smells
____There should be only one return statement at the end of the function?
____function cannot have more than one try statement?
Is the ____ flag argument bad?
____Global variables are bad?
____Comments are unnecessary?
__organize

Chapter 6: How to Write Python-Like Code
__Python's Zen
__Meaningful indentation
__Commonly Misused Phrases
Use enumerate() rather than ____range()
Use the with statement rather than ____open() and close()
Let's use is instead of ____== to compare with None.
__String formatting
If your ____string contains many backslashes, use raw strings.
String formatting using ____f-strings
__Create a shallow copy of a list
__How to use Python dictionaries
Let's use get() and setdefault() in the ____dictionary
____Use collections.defaultdict for default values
Let's use dictionaries instead of ____switch statements.
__conditional expressions: Python's 'ugly' ternary operator
__Variable value operation
____Chaining assignment and comparison operators
Check if a variable ____ is one of several values
__organize

Chapter 7: Programming Terminology in the Python World
__Definition of various terms
____Python as a programming language vs. Python as an interpreter
____Garbage Collection
____literal
____Keyword
____object, value, instance, id
____item
____mutable data type, immutable data type
____Index, Key, Hash
____Container, sequence, mapping, and set types
____double underscore method, magic method
____module, package
____callable object, first-class object
__A term often used interchangeably
____ statement vs. expression
____Block vs. Section vs. Body
____variables vs. properties
____Function vs. Method
____Iterable Objects vs Iterators
____Syntax error vs. runtime error vs. semantic error
____Parameters vs. Arguments
____Type coercion vs. type casting
____Property vs. Attribute
____Bytecode vs. Machine Code
____Script vs. Program, Scripting Language vs. Programming Language
____Library vs Framework vs SDK vs Engine vs API
__organize
__Additional information

Chapter 8: Common Pitfalls in Python
__Do not add/delete items from the list while the loop is in progress.
Don't copy mutable values ​​without __copy.copy() or copy.deepcopy()
__Do not use mutable objects in default arguments
__Do not create strings by concatenating strings
Don't expect __sort() to sort alphabetically.
__Don't assume floating point numbers are perfectly accurate
__Do not use the inequality operator != consecutively
__Don't forget the comma in single-item tuples
__organize

Chapter 9: Python's Weird Features
Why is __256 is 256 true but 257 is 257 not true?
__String Interning
__Python's fake increment/decrement operator
__all() is true if there is nothing
__Boolean value is an integer value
__Writing multiple operators in succession
__Python's antigravity function
__organize

Chapter 10: Creating Python-like Functions
__function name
__Function size tradeoff
__Function parameters and arguments
____default arguments
Passing arguments to functions using ____* and **
Creating a variable argument function using ____*
Creating a variable argument function using ____**
Creating wrapper functions with ____* and **
__Functional programming
____side effect
____higher-dimensional function
____Lambda function
Mapping and filtering using ____list comprehensions
__The result value must always be of the same data type.
__Raising an exception vs. returning an error code
__organize

Chapter 11: Comments and Type Hints
__annotation
____Comment Style
____inline comments
____Explanatory Notes
____Summary Notes
____Annotations containing experiential knowledge
____Annotations containing legal information
____Professional Comments
____Code tags and TODO comments
____Magic Annotations and Source File Encoding
__docstring
__Type Hint
____Use static analysis tools
Setting ____type hints to multiple types
____Setting type hints for lists, dictionaries, etc.
Backporting type hints using ____ annotations
__organize

Chapter 12 Code Management Techniques Using Git
__Git commits and repos
__Creating a new Python project using the cookiecutter package
__Git installation
____Set your Git username and email
Installing ____GUI Git Tools
__Git Workflow
____How Git Manages File State
Why do I need to move the ____ file to a staging state?
__Create a Git repo on your computer
Add and manage files with ____git
Ignore specific files in ____repo
____Commit changes
____Delete files from the repo
Renaming and moving files in ____repo
__View commit log
__Restore to previous change history
____Discard uncommitted local changes
____Release staged files from staging status
____Rollback the most recent commit
____Rollback a single file to a specific commit
____Rewrite commit history
__GitHub and the git push command
____Push an existing repository to GitHub
____Clone a repo from an existing GitHub repo
__organize

Chapter 13: Algorithm Performance Analysis and Improvement Using Big O
__timeit module
__cProfile profiler
__Big O Algorithm Analysis
__Big O degree
Understanding Big O using the example of organizing a bookshelf
Big O, which measures the worst-case scenario
Let's figure out the Big O degree of __code.
____Why we ignore low orders and coefficients
____Big O Analysis Example
____Big O order of a typical function call
____Big O at a glance
Big O is meaningless when ____n is small, and n is generally small.
__organize

Chapter 14: Hands-on Projects: Tower of Hanoi and the Four-Handed Game
__Hanoi Tower Game Project
____Screen output contents
____source code
____Write code
__Pastoral Game Project
____Screen output contents
____source code
____Write code
__organize

[Part 3] Python and Object-Oriented Programming
Chapter 15: Object-Oriented Programming and Classes: Learning through Tic-Tac-Toe
__Real-world analogy: filling out an online form
Creating an object from a __class
Create a simple class called __WizCoin
____method, __init__(), self
____attribute
____Private properties and private methods
__type() function and __qualname__ attribute
Comparing Object-Oriented and Non-Object-Oriented Programming: Tic-Tac-Toe
__Designing classes for the real world is difficult
__organize

Chapter 16: No More Code Duplication! Solve It with Inheritance
__How inheritance works
____Method Override
____super() function
____Synthesis rather than inheritance
Disadvantages of ____inheritance
__isinstance() and issubclass() functions
__class method
__class attribute
__static method
__When using classes and static object-oriented features
__Object-oriented terminology
____encapsulation
____polymorphism
__When not to use inheritance
__Multiple inheritance
__Method Decision Order
__organize

Chapter 17: Object-Oriented Programming in Python
__property
Convert ____attribute to property
____Using setters for data validation
____Read-only property
When to use the ____ property
__Python's double underscore method
____String expression double underscore method
____Number double underscore method
____Mirror Number Double Underscore Method
____In-place swap augmentation substitution double underline method
____Compare double underline method
__organize

Detailed image
Detailed Image 1

Publisher's Review
| What this book covers |
● How to write clean code using Python's black automatic formatting tool, including coding style
● Identifying the causes of common bugs and detecting bugs using static analyzers
How to structure your code project's files using the Cookie Cutter template tool.
● Functional programming techniques for higher-order functions such as lambda
● Profiling code speed with Python's built-in timeit and cProfile modules
● How to make comments and docstrings useful information and when to write them

| Structure of this book |
This book goes beyond simply covering Python syntax in depth, and also covers a variety of command-line tools used by professional developers, including command lines, code formatters, linters, and version control.
We've covered what makes code readable and how to write truly clean code, and you'll work through a few programming projects to see how these principles apply to real-world software.
Although this book is not a computer science textbook, it also covers topics such as Big O algorithm analysis and object-oriented design.

[Part 1] Preparation

Chapter 1: Understanding Error Messages and Asking Questions to Get Help from Experts

Shows you how to effectively ask questions of others and find the answers you need on your own.
It also teaches you how to read error messages and the etiquette of asking for help online.

Chapter 2: Setting Up the Environment and Using the Command Line
We'll look at how to navigate the command line, including setting up your development environment and setting up the PATH environment variable.

[Part 2] Best Practices, Tools, and Techniques for Clean Code

Chapter 3: Establishing Coding Style and Automating Code Formatting

We'll look at the PEP 8 style guide and code formatting to improve readability.
You'll also learn how to automate this process using Black, a code formatting tool.

Chapter 4: Easy-to-understand names
Learn how to name variables and functions to improve code readability.

Chapter 5: Detecting and Responding to Code Smells
We'll cover some potential warning signs that might indicate there may be bugs in your code.

Chapter 6: How to Write Python-Like Code
We'll look at some conventions for writing Python code and how to create Pythonic code.

Chapter 7: Programming Terminology in the Python World
Learn about the technical terms and frequently confused terms used in the programming field.

Chapter 8: Common Pitfalls in Python
Covers the causes of common confusions and bugs in the Python language, solutions, and coding strategies to avoid them.

Chapter 9: Python's Weird Features
We'll cover some of the weirdest features of the Python language you might not know about, like string interning and the anti-gravity Easter egg.
Understanding why certain data types and operators cause such unexpected behavior will deepen your understanding of how Python works.

Chapter 10: Creating Python-like Functions
Learn how to structure your functions to maximize usability and readability.
Learn functional programming techniques such as * and ** argument syntax, pros and cons of large and small functions, and lambda functions.

Chapter 11: Comments and Type Hints
The program addresses the importance of non-code portions and their impact on maintainability.
Explains how often you should use comments and docstrings and how to make them useful.
In this chapter, we'll also learn how to detect bugs using type hints and static analyzers like MyPy.

Chapter 12 Code Management Techniques Using Git
Learn how to use Git version control tools to record source code changes, revert to previous versions of your work, or trace the origins of bugs.
We'll also cover how to use the cookie cutter tool to organize the files in your code project.

Chapter 13: Algorithm Performance Analysis and Improvement Using Big O
Learn how to objectively measure the speed of your code using the timeit and cProfile modules.
We also cover how to use Big O algorithm analysis to predict how much your code will slow down as the amount of data it needs to process increases.

Chapter 14: Hands-on Projects: Tower of Hanoi and the Four-Handed Game
We'll apply the techniques we've learned so far by writing two command-line games.
Hanoi Tower, a puzzle game where you move a disk from one tower to another, and Samok, a time-honored two-player board game.

[Part 3] Python and Object-Oriented Programming

Chapter 15: Object-Oriented Programming and Classes: Learning through Tic-Tac-Toe

Defines the often misunderstood role of object-oriented programming (OOP).
Many developers overuse OOP techniques in their code because they think everyone else is doing it, which is a major cause of source code complexity.
This chapter teaches you how to write classes, but more importantly, it explains why you should and should not use classes.

Chapter 16: No More Code Duplication! Solve It with Inheritance
Learn about class inheritance and how useful it is for code reuse.

Chapter 17: Object-Oriented Programming in Python
Covers Python's unique object-oriented design features, such as properties, double-underlined methods, and operator overloading.

[Recommendation]

My first Python program works too.
But if I had read this book earlier, things would have been much better.
This book is a goldmine of valuable knowledge that will be helpful to beginners, intermediate developers, and even advanced programmers.
- GeekTechStuff

This book is packed with useful information for every Python developer.
For anyone looking to learn the fundamentals of coding, especially Python coding, what better book could there be?
- Ian Mizer / Atlanta Python Programmers Group

This is a really great book.
Author Swaigart focuses on three topics: the initial challenges developers often face (asking for help, setting up a work environment), programming best practices and tools and techniques, and finally, leveraging object-oriented Python.
This book is especially useful because it provides a clear overview of the information you would otherwise have to search through in many places.
- Serdar Yegulalp / InfoWorld

[Author's Note]

It would be a mistake to view this book as simply a collection of useful tips for writing clean code.
This book will take you through the command line and show you how to use various specialized tools such as code formatters, type checkers, linters, and version control.
Author Al Swaigat shares his knowledge and expertise, covering everything from development environment setup, variable naming, and best practices for readability, to documentation, code organization, performance measurement, object-oriented design, and Big O algorithm analysis.
The intermediate and advanced techniques taught in this book are useful not only in Python but in all languages ​​and will greatly enhance your programming skills.
No matter how good a book is, you can't become a professional software developer just by reading it, but this book clearly guides you on how to write code that's easy to debug, Pythonic, and readable.
The path to becoming an expert is soon upon you.

[Translator's Note]

Since the publication of Robert C. Martin's "Clean Code: The Art of Agile Software Craftsmanship," developers' interest in writing clean code and refactoring has been growing day by day.
The ease of maintenance and extensibility of functionality provided by readable code are recognized as software attributes that should be pursued not only by developers working with legacy code but also by developers starting a project from scratch.
To this end, various practical methods and best practices are being shared, and the advancement of integrated development environments (IDEs) can even benefit from automation.
But even in this ripe atmosphere and environment, if you feel something is lacking by 2%, it is not just your problem.
Like any other programming language, Python is easy to learn but difficult to master.
Especially compared to other programming languages, Python's high-level nature makes it relatively easy to get started, opening the eyes of novice developers to the many possibilities they can create with computers. However, when they actually encounter real-world problems and try to solve them, they are shocked to realize that Python is by no means easy.
Is it a problem with the Python language itself? Or with its complex libraries and frameworks? Or is it a problem with my basic lack of understanding of underlying computer science? How do truly advanced users use Python, and what secrets do they learn in the process that I don't?
As the title, "Clean Code, Now in Python," suggests, it introduces how to apply clean code to Python to create Python-like code.
Rather than simply transplanting the content covered in existing clean code books and online documentation to Python, this book identifies the obstacles that beginner developers must overcome on their way to becoming competent developers, and presents a variety of examples and tips on how to overcome them in a standard manner.
This book introduces practical tips and industry-specific tricks for finding information and using the command line like a pro, naming important to clean code, following Python-like guidelines for coding style and formatting, eliminating code smells, writing efficient functions, comments and type hints, and avoiding Python's quirks and pitfalls.
Additionally, to strengthen your computer expertise, it covers various programming terms, essential version control methods you must know, theories and tools for measuring algorithm performance, and explanations of object-oriented programming.
Building on the knowledge acquired in the previous chapters, the book provides a step-by-step guide to expanding a simple game in a Python-like object-oriented manner, allowing readers to develop a sense of progressive and scalable software development.
While this book may not offer groundbreaking breakthroughs, it's packed with valuable content that will motivate developers who want to improve their skills little by little every day, provide a starting point, and lay a solid foundation so they won't be afraid when faced with challenges.
If you read this book, put what you learn into practice, and repeat the process of adapting it to your own style, you will find yourself transformed into a professional software developer at some point.
I sincerely hope that this book will be a great teacher and good friend to you on your development journey.
- Park Jae-ho

Compared to languages ​​like Java, Golang, and C++, Python has its own unique characteristics.
Although it is more accessible and easier to explain and understand than other languages, it has the disadvantage of being slower than other languages ​​in algorithm coding tests, and some developers express difficulty in debugging.
When using the term "Python expert," even experienced developers often find it difficult to explain what skills and understanding a Python expert possesses, or what steps a junior developer can take to become a Python expert.
This book is far from an introductory book to Python.
However, I also keep my distance from overly academic books.
The author's concerns about how to bridge the gap between beginner and expert are evident throughout.
This book neither uses difficult decorators nor uses extreme shorthand lambdas.
However, it does offer several methods that beginners can try to take it one step further.
- Kim Dong-hyun
GOODS SPECIFICS
- Date of issue: August 16, 2022
- Page count, weight, size: 440 pages | 824g | 185*240*21mm
- ISBN13: 9791189909451
- ISBN10: 1189909456

You may also like

카테고리