liveBook · Manning

Code readability

As explained in Get Programming: Learn to code with Python

Code readability is the ease with which human readers can perceive and understand source code, including its structure and intent.

Readable code helps other people—and your future self—understand what a program is meant to do. Descriptive names can make the intent clearer than short, unexplained names. section 2.4

pi = 3.1
radius = 2.2
# use the formula to calculate the area of a circle
circle_area = pi * radius * radius

Compare this version with the less descriptive a, b, and c version: names like radius and circle_area make the calculation easier to recognize. The comment gives the reason for the calculation, rather than just repeating what the code does. section 2.4

Readable code also separates complex calculations from conditionals. Give a calculation a descriptive variable name, then use that name in the condition. In Python, indentation makes code blocks visible and helps readers follow which lines belong together. section 14.2

How Get Programming: Learn to code with Python covers it

How deep it goes
Demonstrates meaningful names, explanatory comments, and named computations, without developing a broader set of readability rules.
Examples
Uses circle-area code and conditional expressions to contrast descriptive names with opaque or embedded computations.
What you can do after
Apply descriptive names and explanatory comments, and give complex computations names before using them in conditionals.
How it connects
Connects code readability with variable names, comments, conditionals, and indentation.

Also explained in

Compare how 11 books explain code readability →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Get Programming: Learn to code with Python. The section links point to the parts of the book it draws on.