10. Low-level Design

Best practices for organizing functionality.

Motivation

We make references to “writing code the right way”, but that is secondary to getting the correct answer. After all, how can you get a good grade if it doesn’t work?

In software engineering, everything needs to work, but doing it the right way is equally important. Why?

  • Because you are on a team, and someone else may have to understand and edit your code. Including your future self. We call this understandability.
  • Poorly-implemented solutions are more difficult to change without introducing bugs. We call this maintainability.
  • Poorly-implemented solutions may work with small data, but become intolerable with millions of records. We call this efficiency.
  • Overly-specific solutions that make assumptions about the data will break when encountering “the real world”. Avoiding this is called robustness.

The Rules

These characteristics are the result of your code design. The labs in these sections will go through code-level design principles that you, the developer, are responsible for when writing code.

The rules are:

  1. Avoid magic literals.
  2. Functions should have a single responsibility.
  3. DRY (Don’t Repeat Yourself) and the Rule of Three.
  4. Separate input/output logic from business logic.
  5. Handle errors at the lowest sensible level, and re-raise/re-throw them otherwise.
  6. Raise specific errors and define your own if needed.

Write these down! We will explore them in-depth in turn. We will start by creating a simple game, then applying design rules to it.

Click below to get started.


pygame setup

Getting started with a game.

Avoid magic literals

Best practices for organizing functionality.

Last modified October 27, 2025.