GCSE · Computer Science · OCR · Spec J277
Maintainability: naming conventions
Your program works. Brilliant. Now ask a friend what x, h and s are for. The computer never needed good names. The humans reading your code do.
Sort the names
Suitable, poor or not allowed?
Pick a name, then pick where it belongs.
Still to sort
Suitable (0)
Shows what it holds and follows the Python convention.
Where the line is: Allowed isn't enough to land here. The name has to tell a reader what it holds AND be written the Python way: lower case, underscores between words.
Allowed, but poor (0)
Breaks no rule, but doesn't show what it holds or ignores the convention.
Where the line is: These names would be accepted. The trouble is the human reading the code, not the language.
Not allowed at all (0)
Breaks a non-optional rule, such as having a space or starting with a number.
Where the line is: This is about rules, not style. Breaking a rule means the name isn't allowed, however meaningful it is.
Nine names a Python programmer suggested for three variables. Judge each one before you see why.
Read the code
Two lines of Python. Commit to an answer before you look.
A program starts with x = 0 and later runs x = x + 1. What is x counting?
WHAT YOU'VE LEARNED
A quick recap of today's lesson.
A good name tells the reader what it holds, so the code explains itself.
What you need to know
- An identifier is the name a programmer gives to a variable, a constant or a subroutine.
- Give variables meaningful names, so a human can read and follow the program much more easily.
- Meaningful identifiers make code self-documenting: the code explains itself.
- A naming convention is a standard way of writing identifiers, and most programming languages have their own.
- Some naming standards are non-optional rules: for example, a variable name can't include a space or start with a number.
Have a goThree names: total score, total2, 2total. Which ones aren't allowed?
total score and 2total.
One has a space and the other starts with a number. total2 has its number at the end, which breaks neither rule.
- Python's convention for variable names is lower case with underscores between words. That's snake case: last_name, pupil_id.
Have a goYour friend proudly names a Python variable PUPILNAME. "It's meaningful!" he says. What would you change it to?
pupil_name
He's right that it's meaningful, but that's only half the job. Python's convention is lower case with an underscore between the words.
- A suitable identifier shows what it holds and follows the convention: score, not x; height_in_feet, not h.
- Ignore good naming and code can become difficult to maintain or fix, and other programmers may not understand it.
Have a goA teammate wrote 200 lines using only a, b and c, then went on holiday. There's a bug. What's your first problem?
Working out what each variable holds before you can fix anything.
Poor names make code difficult to maintain or fix, and other programmers (that's you now) may not understand it.
The big picture
An identifier is the name you give a variable, constant or subroutine. Some naming rules aren't optional, like no spaces and not starting with a number. Beyond that, a suitable name shows what it holds and follows the language's convention, which in Python is snake case. Good names make code self-documenting; poor ones make it hard to maintain, fix or understand.
Key points
Worked example
Problem
A Python program needs a variable to store a pupil's ID. Three names are suggested: pupil id, PupilID and pupil_id. Which one is the suitable identifier, and what's wrong with the other two?
⚠ Watch out
Thinking a name is fine just because the program runs. x is allowed as a name for a score, but it's still a poor identifier: it doesn't show what it holds, so the code is harder to read, maintain and fix.
Memory hook
Can I? Should I? Will they get it? Rules decide if a name is allowed, the convention decides how to write it, and meaning decides whether the next reader understands it.
Check yourself
Without looking back: a variable stores the number of lives a player has left. Is lives_left a better identifier than LL, and can you give two reasons why?
Flashcards
(12)What is an identifier?
Apart from variables, what else gets an identifier?
Why give variables meaningful names?
What does self-documenting code mean?
What is a naming convention?
Give two non-optional rules for variable names.
What is Python's naming convention for variables?
Write 'pupil id' as a Python variable name.
Which is better for a score: x or score? Why?
Better name than h for a height measured in feet?
What can happen if programmers don't use meaningful names?
Breaking a rule vs breaking a convention: what's the difference?
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.