09. Code Readability

Making code easier to understand.

You are getting the first edition of all these pages. Please let me know if you find an error!

Motivation

Learning to program often focuses on syntax and semantics – avoid errors and get the correct answer.

You probably also learned about rules to follow for how your code looks. You were probably also told that you should write good comments. Why?

A tremendous amount of research in programming language development and in software engineering focuses on program comprehension a.k.a., understandability. How much effort does it take to understand your source code? Software engineers care deeply about understandability because most of the effort in software development is spent fixing bugs or adding functionality to existing code. To do that without breaking everything, you need to understand what the existing code does!

Understandable code is a function of several things:

  1. The programming language syntax and semantics. Python is objectively more human-friendly than assembly language.
  2. Coding conventions and documentation.
  3. Design and organization of the code.

We are going to focus on #2 first and #3 in the future.

Both coding conventions and code documentation promote readability: how difficult is it for someone to read your source code and understand it. Let’s look at these topics separately.


Coding conventions

Readability is a function of names and style.

Documenting code

Properly commenting your code goes a long way toward understandability.

Last modified October 2, 2024.