Agenda
Six Key Points of Senior Python Code Review
Supportive Environment and Tools around
Pull-Request
1.
2.
2023 talk in
PyCon TW
Slide 3
Slide 3 text
Anti-Agenda
How-to Details
Find A Good Job
ποΈ π ποΈβπ¨οΈ π π π¦
1.
2.
Slide 4
Slide 4 text
Been
there
reviewed
that?
You've got a review
Slide 5
Slide 5 text
Pull-Request (PR)
> A pull request is a method used in
collaborative coding projects to propose
code changes.
> It allows developer to request code review,
and then merge those changes into the main
code repository once approved.
Slide 6
Slide 6 text
Keith Yang
Lead Backend Engineer in iCHEF
Taipei.py co-founder and co-organizer
PyCon APAC 2015 Chairperson
Lead Backend Engineer in iCHEF
Taipei.py co-founder and co-organizer
PyCon APAC 2015 Chairperson
Slide 7
Slide 7 text
No content
Slide 8
Slide 8 text
No content
Slide 9
Slide 9 text
6 Key Points
of
Senior Python
Code Review
Agenda 1
Slide 10
Slide 10 text
6 Key Points
of
Senior Python
Code Review
Agenda 1
9,999
From Years of Practice
Slide 11
Slide 11 text
Code Review
Slide 12
Slide 12 text
Quality Assurance
Knowledge Sharing
Finding and Fixing Bugs Early
Code Review
Slide 13
Slide 13 text
... to submit a change
to the kernel,
... can be daunting
... if not familiar with
"the system"
- Submitting patches guide (Linux kernel)
git send-email
Slide 14
Slide 14 text
No content
Slide 15
Slide 15 text
No content
Slide 16
Slide 16 text
#Comment
Code Readibilirty
Make code
easy to be
understood
If it's tricky, write
comments to help
understanding
1st key point
Slide 17
Slide 17 text
GUESSING
GUESSING
PURPOSE
PURPOSE
Slide 18
Slide 18 text
#Comment Example 1
Slide 19
Slide 19 text
No content
Slide 20
Slide 20 text
#Comment Example 1
Slide 21
Slide 21 text
#Comment Example 2
Slide 22
Slide 22 text
Concise Code
Descriptive for Human
Purpose instead of Function
2nd key point
Slide 23
Slide 23 text
Code Example
Slide 24
Slide 24 text
Naming
Descriptive for Human
Purpose instead of Function
Uniqueness v.s. Common
easy to understand
3rd key point
Slide 25
Slide 25 text
Uniqueness
"user" in users.py
"member" in members.py
"user" in crm.py
"member" in crm.py
Easiest to find and reason?
a.
b.
c.
d.
Slide 26
Slide 26 text
Uniqueness
"user" in users.py
"member" in members.py
"user" in crm.py
"member" in crm.py
Easiest to find and reason?
a.
b.
c.
d.
Tool: ripgrep
Slide 27
Slide 27 text
EXAMPLE
Naming in member_logic.py,
not member_utils.py
Slide 28
Slide 28 text
Code & Infra
Readability
Make code
and module
easy to
understand
If it's tricky, write
comments and doc
to help
understanding
Slide 29
Slide 29 text
The Zen
of
Python
The Zen
of
Python
Slide 30
Slide 30 text
python3 -m this
The Zen
of
Python
Slide 31
Slide 31 text
Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!
The Zen of Python, by Tim Peters
python3 -m this
Slide 32
Slide 32 text
Beautiful is better than
ugly.
Explicit is better than
implicit.
Simple is better than
complex.
CODE
CODE
NAMING
NAMING
COMMENT
COMMENT
Slide 33
Slide 33 text
CODE
NAMING
COMMENT
Readability counts.
...easy to explain, it
may be a good idea
Namespaces are one
honking great idea
Slide 34
Slide 34 text
6 Key Points
of
Senior Python Code Review,
Part II
Senior Wrote Knew
Common Python Errors
Defaults for function
arguments
Modifying a list while iterating
over it
Lambda in for loop?
MISTAKES
5th key point
Slide 39
Slide 39 text
Been
there
Done
that
π₯²
Slide 40
Slide 40 text
Lambda Code
EXAMPLE
in ITERRATION
Expecting [0, 1, 2, 3, 4]?
Slide 41
Slide 41 text
PEP8
Read the doc?
Tools
black, isort
flake8, ruff
pre-commit
6th key point
Slide 42
Slide 42 text
PEP8 Check
Real-time in Vim EXAMPLE
Slide 43
Slide 43 text
Type Hint
Does Python
need type hint?
extra key point
Slide 44
Slide 44 text
Type Hint
But it can be used to
find mistakes early
Small Projects
v.s. Large Enterprise Projects
No.
extra key point
Slide 45
Slide 45 text
Supportive
Environment
and Tools
around
Pull-Request
Agenda 2
Slide 46
Slide 46 text
βOne essential characteristic of modern life
is that we all depend on systemsβ
-- The Checklist Manifesto: How to Get Things Right
by Atul Gawande
Slide 47
Slide 47 text
Why to and why not
Commit Message
Pull-Request Description
Document File
Documentation
Documentation
Complete the Code Review
Slide 48
Slide 48 text
Purposes
and
Reasons
Implement
Plan
Do This
Bο»Ώ
efore
Coding
Design Review
Design Review
Complete the Code Review
Slide 49
Slide 49 text
Template Rocks
π€
Design Review
From Years of Practice
Slide 50
Slide 50 text
Operation Review
Scop
User Stories
Security Review
Inspirations
Success Criteria
B Plan (if not working)
Designs
(API, Model, DB)
Performance Review
Alternatives
Considered
Template Example
& Tips
Errors should never
pass silently
Unless explicitly
silenced
Special cases aren't
special enough to
break the rules
DOCUMENT
DOCUMENT
TEMPLATE
TEMPLATE
CI / CD
COVERAGE
CI / CD
COVERAGE
Slide 63
Slide 63 text
Errors should never
pass silently
Unless explicitly
silenced
Special cases aren't
special enough to
break the rules
DOCUMENT
DOCUMENT
TEMPLATE
TEMPLATE
CI / CD
COVERAGE
CI / CD
COVERAGE
TYPE HINT
TYPE HINT
Slide 64
Slide 64 text
DOCUMENT
TEMPLATE
CI / CD There should be one
-- and preferably only one --
obvious way to do it.
TYPE HINT
Slide 65
Slide 65 text
AI Tools
GPT4
ChatGPT
Bard
Claude
GitHub Copilot
Slide 66
Slide 66 text
AI Tools
Prompt vs real experienced
Domain Knowledge
Identify what's right and
wrong with official doc
Experiment tools and grow
with your team
Slide 67
Slide 67 text
Mentorship
Design Review
Weekly Meeting
Sharing Fun and Pain
Teamwork
Slide 68
Slide 68 text
Internet
AI
Books, Podcast, Video
(ο»Ώ
O'Reilly Learning)
Communities & (Py)Cons
Different Languages &
Design Paradigms & Pitfalls
def Learning(self)
Taiwan
/APAC
Slide 69
Slide 69 text
Search on Internet
Reference vs Pragmatic
Mentor & Boss
Interview & Culture
Care Framework
Care Framework
Ladder: Your Mileage May Vary
Slide 70
Slide 70 text
Summary
From Comment to Naming: Explicit
Common Errors
Supportive Environment with Tools:
Find Errors at Very First Place
Design Template
CI/CD, AI, Soft Skills
Senior: More Helpful
Slide 71
Slide 71 text
OF SENIOR
ENGINEERS
CODE REVIEW
PYTHON
@keitheis @mstdn.io π
discord
@keitheis @mstdn.io π
discord
Keith Yang