GCSE · Computer Science · Edexcel · Spec 1CP2
Code readability techniques
Two programs do exactly the same job. One makes sense at a glance; the other looks like someone fell asleep on the keyboard. Which would you rather fix next term?
Computer Science · What the computer sees
Watch the interpreter skip the helpful bits
Step through this Python program. Notice which lines the highlight lands on and which it jumps over.
WHAT YOU'VE LEARNED
A quick recap of today's lesson.
The computer doesn't care how your code looks. The humans who read it really do.
What you need to know
- Good programming practice means making code easy for anyone to read, understand, improve and maintain later.
- The four practices to know are comments, program layout, identifiers and naming conventions.
- Readable code matters because engineers work in teams, others may adapt it, and you may forget it after time away.
Have a goYour mate says: "It runs, so who cares what it looks like?" Name one person who might care in a year's time.
Another programmer on the team, someone adapting it, or you, after time away.
Code gets read and changed long after it is written, so working today is not the same as being easy to maintain.
- A comment is text in the code that the compiler or interpreter ignores; it is there for the human reader.
- Comments explain what is not obvious or summarise a subroutine, at the end of a line or on the line before.
Have a goWhich one needs a comment more: the line count = count + 1, or a ten-line subroutine that works out a pupil's grade?
The ten-line subroutine.
Comments earn their place by explaining what is not obvious or summarising a subroutine; count = count + 1 already explains itself.
- Separate sections with whitespace (return and space characters), such as a blank line between an assignment and the selection after it.
- Indentation is part of layout. In Python it is essential syntax that decides how the program runs.
- In other languages indentation isn't required, but code without it is harder to read.
- Identifiers are the names for variables, constants and subroutines. Meaningful ones make code self-documenting: score beats x.
- Some naming rules are non-optional: no spaces and no starting with a number. Python's variable convention is snake case, like last_name.
Have a goA classmate names a variable 3rd_goal and says it describes the goal perfectly. Will Python accept it?
No. A name can't start with a number.
Being meaningful is not the same as being allowed: the naming rules are non-optional, so a clear name can still be illegal.
The big picture
Code has two audiences: the computer, which only needs it to run, and people, who need to read, fix and change it. Comments, whitespace, indentation and well-chosen names are how you look after the people. In Python indentation also decides how the program runs.
Key points
Worked example
Problem
This program works, but it is hard to read. Improve its readability without changing what it does. h=float(input("Height in metres: ")) if h>=1.2: print("You can ride") else: print("Too short")
⚠ Watch out
Thinking "it runs, so it's finished". A name can run and still be a poor name (x), a name can be meaningful and still be illegal (2nd_score), and in Python indentation is never just decoration.
Memory hook
Write for the next human who opens the file. The computer copes either way, except in Python, where the indentation is both the layout and the logic.
Check yourself
Take x = int(input()) in a program with no comments. Name one change that would help a reader and say what it tells them.
Flashcards
(13)What is good programming practice?
Name four good programming practices.
Why does readable code matter?
What is maintainability?
What is a comment?
What should a comment explain, and where can it go?
What is whitespace used for in layout?
How does indentation differ between Python and other languages?
What is an identifier?
What does self-documenting code mean?
Give a better identifier than h for a height in feet.
What is a naming convention, and which parts are non-optional rules?
What is Python's convention for variable names?
Tap any card to flip it, or use Study as deck to go through them one at a time. In the full lesson these run as a spaced-repetition deck — you rate each card Hard, Good or Easy and the tricky ones keep coming back until they stick.
Learning with Lightbulb is opening soon
You can use this lesson now. Join the waitlist and we'll let you know when the full Lightbulb experience is ready.
Keep me postedMore Edexcel GCSE Computer Science topics
- Built-in and user-devised subprograms
- Converting algorithms to programs
- CSV file I/O
- Decomposition and abstraction in programming
- Evaluating program fitness and efficiency
- Functions vs procedures
- Global vs local variables
- Identifying and correcting program errors
- Primitive data types
- Programming – condition-controlled repetition
- Programming – count-controlled repetition
- Programming – iteration over data structures
How this lesson was checked. This Edexcel GCSE Computer Science (specification 1CP2)lesson was published through Lightbulb Learning's human-designed editorial process — the educational standards, accuracy rules and publication checks it must pass were authored and approved by Philip Halpin. It passed subject-specific assessment, automated educational checks and technical publication verification before going live (publication checks completed 21 November 2026). Published pages are monitored, human spot-checking is ongoing across the lesson library, and anything found wrong is corrected or withdrawn. How our lessons are made and checked. Spotted a mistake? Email hello@lightbulblearning.co and we'll review it.