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

2. Expressing Design in Code

For example, using at least one function for each sub-problem.

3. Patterns

  1. Roles of Variables

    1. fixed value
    2. stepper
    3. most-recent holder
    4. most-wanted holder
    5. gatherer
    6. follower
    7. one-way flag
    8. temporary
    9. organizer
    10. container
    11. walker
  2. Code Patterns

    1. Accumulator Pattern
      1. Parts
        1. Initialize
        2. Iterate
        3. Update
      2. Sub-patterns
        1. Transformation Pattern
        2. Filter Pattern
    2. Search Pattern
    3. Sentinel Pattern
    4. DSU Pattern (Decorate-Sort-Undecorate)

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

  1. imports
  2. Consts and globals
  3. Functions and classes
  4. main function

5. Code Sections

  1. Manifestation of the sub-problems breaking in designing a solution
  2. Types
    1. Introductory Code - Special Cases, Dealing with Errors
    2. Main Algorithm
    3. Ending Code - Clean-up and Return

6. Audience

  1. Human - Expository Mode (encourages a discipline)
    1. Other People
    2. You in the Future
  2. Machine

Checkout Question:

Does my code work? Is the code pythonic? Is my code written and documented well (PEP8)?



Copyright © 2020 Shlomi Hod.
All rights reserved.

results matching ""

    No results matching ""