Python

Lesson 01

Naming and readability

Use names and small functions that explain intent without forcing reviewers to decode abbreviations.

Good Code

review_score.py
def calculate_review_score(review):
    comment_score = len(review.comments) * 2
    approval_score = review.approvals * 5

    return comment_score + approval_score

Bad Code

review_score.py
def calc(x):
    a = len(x.c) * 2
    b = x.a * 5

    return a + b

Review Notes

What to review

Good Code

The good version names the function and intermediate values after the business idea, so the scoring rule can be read without reverse engineering attributes.

Bad Code

The bad version hides the domain behind calc, x, a, b, and short attribute names. It may work, but the reviewer has to decode it before checking correctness.

Takeaways

  • Readable Python starts with names that describe the domain, not the implementation shortcut.