in Projects, Programming, Technology

Python Code Review

For today’s passive-agressive-OCD-overgeneralizing-programmer blog post, I’ll code review a data scientist’s python code.

There’s two main points I’d like to get across:

  1. Be consistent 

Programmers follow conventions to make make code easier to understand by requiring less brain power for parsing syntax. I’ve chose python black, because that’s what my team chose. Regardless of the style you choose – be consistent.

In the video I show examples of:

a) Snake case vs camel case (inFile1 should be input_file_name1)

b) url1 has no underscore, data_1 – has an underscore. Just pick one.

c) Spacing should be consistent after commas.

2. Don’t over-abbreviate

Variable names are your chance to make your code more readable! Choose readability over compactness.

a) inFile1 should be input_file_name1

b) url_base should be base_url

C) I have no idea what data_1 is … I think population_data?

d) Where possible, variable names should be nouns, functions should be verbs.

e) import numpy as np (why?!)

That’s it. Remember, the person reading your code (which potentially includes you next week) doesn’t know what’s in the variables – so use the name to describe the contents 🤯.

Related: Why I hate Python

Write a Comment


This site uses Akismet to reduce spam. Learn how your comment data is processed.