3. Code
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." – Martin Fowler
"Code is like humor. When you have to explain it, it’s bad." – Cory House
"Programs must be written for people to read, and only incidentally for machines to execute." — Gerald Jay Sussman and Hal Abelson
"Commenting your code is like cleaning your bathroom - you never want to do it, but it really does create a more pleasant experience for you and your guests." - Ryan Campbell
"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John Woods
"There are only two hard things in Computer Science: cache invalidation and naming things." — Phil Karlton
1. Python Language
- Pythonic Code
- PEP 20 - The Zen of Python
- Python Idioms
- Python Anti-Patterns
2. Expressing Design in Code
For example, using at least one function for each sub-problem.
3. Patterns
-
- fixed value
- stepper
- most-recent holder
- most-wanted holder
- gatherer
- follower
- one-way flag
- temporary
- organizer
- container
- walker
Code Patterns
- Accumulator Pattern
- Parts
- Initialize
- Iterate
- Update
- Sub-patterns
- Transformation Pattern
- Filter Pattern
- Parts
- Search Pattern
- Sentinel Pattern
- DSU Pattern (Decorate-Sort-Undecorate)
- Accumulator Pattern
4. Style & Documentation
1. PEP8
2. Meaningful Names
3. Comments Matter
- Non-obvious features of the code
- Not redundant with the code itself
- Design decision documentation
4. Helper Functions
5. Code File Organization
import
s- Consts and globals
- Functions and classes
main
function
5. Code Sections
- Manifestation of the sub-problems breaking in designing a solution
- Types
- Introductory Code - Special Cases, Dealing with Errors
- Main Algorithm
- Ending Code - Clean-up and Return
6. Audience
- Human - Expository Mode (encourages a discipline)
- Other People
- You in the Future
- Machine
Checkout Question:
Does my code work? Is the code pythonic? Is my code written and documented well (PEP8)?
All rights reserved.