GCSE · Computer Science · OCR · Spec J277
Maintainability: commenting
Months later your program breaks. You open it and think: who wrote this?! You did. Comments are notes from today-you to tomorrow-you.
Computer Science · Commenting
Which comments are worth writing?
Every comment below was written for one short subroutine, bookingCost(tickets, isMember), which works out what a cinema booking costs. The detail shows the line each comment sits with. Sort each one: what is it actually doing for the reader?
Still to sort
Explains a non-obvious part (0)
Tells the reader something the code alone doesn't make clear.
Where the line is: If you could work it out just by reading the line, it isn't explaining anything. It belongs in 'adds nothing'.
Summarises a subroutine or block (0)
Says in one sentence what a whole chunk of code is for.
Where the line is: A summary covers several lines at once; an explaining comment is about one tricky line.
Adds nothing the code doesn't already say (0)
Correct, but it just repeats the code in words.
Where the line is: Being accurate isn't enough. A comment has to tell the reader something they couldn't already see.
Here's the big idea: the compiler or interpreter ignores every comment. They're written for the programmer reading the code. So the only question about a comment is: does it help that reader?
Comments and maintainability
Reason it through
Why does commenting your code make it easier to maintain?
First link · your turn
A programmer opens some well-commented code to work out what it does. What do the comments do for them?
WHAT YOU'VE LEARNED
A quick recap of today's lesson.
Notes in your code that the computer ignores, but every programmer who reads it (including future you) will thank you for.
What you need to know
- A comment is text in your source code that the compiler or interpreter completely ignores.
- Comments are written for people: they help programmers understand the code.
Have a goPredict: you add fifty comments to a program that already works. Does it run any differently?
No. It runs exactly the same.
The compiler or interpreter ignores comments, so they change nothing about how the program runs. They only change what a human reader sees.
- That means a comment earns its place by helping the reader understand something.
- Use comments to explain parts of the code that aren't obvious.
- Use them to summarise what a subroutine, or a particular piece of code, does.
Have a goYour mate Sam writes score = 0 and adds // set score to 0. "Best comment ever," he says. Is he right?
Not really. It adds nothing.
It's accurate, but the code already says exactly that. A comment earns its place by explaining something non-obvious or summarising a chunk of code.
- Put a comment at the end of the line it's about, or on the line immediately before it.
- Space comments carefully, so it's obvious which comment goes with which line of code.
Have a goA comment explaining line 5 has ended up on line 6, directly above line 7. Which line will a reader probably think it's about?
Line 7.
A comment sits at the end of its line or on the line immediately before it, so one sitting above line 7 looks like it belongs to line 7, not line 5.
- Readable code is easier to maintain. Maintainability means how easily maintenance, like correcting errors, can be done.
- Skip comments and code gets hard to maintain or fix, and other programmers may not understand it.
- Even the person who wrote the code may struggle to understand it after time away from it.
The big picture
A comment is text in source code that the compiler or interpreter ignores; it's there to help programmers understand the code. Good comments explain the parts that aren't obvious, or summarise a subroutine or a piece of code, and they sit at the end of the line they relate to or on the line immediately before it, spaced so it's clear which line they belong to. That makes code more readable, so it's easier to maintain. Maintainability is how easily maintenance, such as correcting errors, can be done. Without comments, code gets hard to maintain or fix, for other programmers and for the original programmer too.
Key points
Worked example
Problem
This subroutine has no comments. Decide where comments would genuinely help, and write them. function canRide(height) if height >= 120 then return true else return false endif endfunction
⚠ Watch out
Thinking a comment is useful just because it's accurate. print(name) // print the name is true, but it only repeats the code. A useful comment explains what isn't obvious, or summarises a subroutine or a piece of code.
Memory hook
Write every comment for future you. The computer skips it; future you is the one who'll read it.
Check yourself
Open a program you've written. Add a comment where a line isn't obvious, then delete one that only repeats its line.
Flashcards
(8)What is maintainability?
What is a comment?
How do comments make code easier to maintain?
Name the two jobs a useful comment does.
Where can a comment be placed?
Why does careful spacing of comments matter?
Give three consequences of not commenting code.
What's wrong with a comment that just repeats what its line does?
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 OCR GCSE Computer Science topics
How this lesson was checked. This OCR GCSE Computer Science (specification J277)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 3 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.