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.

9 of 9 still to sort.

Nine names a Python programmer suggested for three variables. Judge each one before you see why.

Rule or convention?

Non-optional naming rulevsNaming convention

This is the difference people mix up most. Read across each row.

Focus

What it is

Non-optional naming rule

Something every name has to obey. You don't get a choice.

Naming convention

A standard way for identifiers to be written in code. Most programming languages have their own.

The insight

One is a must. The other is the agreed way of doing it, so don't assume every language writes names like Python does.

Examples

Non-optional naming rule

No spaces in a variable name. It can't start with a number.

Naming convention

In Python, variables are lower case with underscores between words: snake case, like pupil_id.

If you break it

Non-optional naming rule

The name isn't allowed.

Naming convention

The name is allowed, but it isn't a suitable identifier.

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 do you think?

It runs. Does the naming matter?

Sam's program works perfectly. Every variable in it is a single letter: a, b, c and so on. Sam says, "It runs, so the names don't matter."

Which is closest to what you think right now?
How sure are you?

Your turn

Rename the variables

LN = input("Enter last name: ") h = input("Enter height in feet: ") s = 0 s = s + 10 print("Score:", s)

This Python code works, but its identifiers are poor. Write a suitable identifier for each of LN, h and s, then explain why one of your new names is better than the original. [4 marks]

0 words · your answer stays on this page and is not sent anywhere.

Exam line: Every new name needs to do two jobs: show what it holds, and be written in Python's snake case.

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

1Identifier = the name given to a variable, constant or subroutine.
2Rules (no spaces, can't start with a number) decide whether a name is allowed at all.
3Conventions are the standard way of writing names; in Python, variables use snake case.
4Suitable = shows what it holds + follows the convention.
5Meaningful names make code self-documenting and easier to maintain and fix.

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?
The name a programmer gives to a variable, a constant or a subroutine.
Apart from variables, what else gets an identifier?
Constants and subroutines.
Why give variables meaningful names?
They make the program much easier for a human to read and follow.
What does self-documenting code mean?
The code explains itself, because its identifiers are meaningful.
What is a naming convention?
A standard way for identifiers to be written in code. Most programming languages have their own.
Give two non-optional rules for variable names.
No spaces, and it can't start with a number.
What is Python's naming convention for variables?
Lower case, with an underscore separating the words. It's called snake case.
Write 'pupil id' as a Python variable name.
pupil_id
Which is better for a score: x or score? Why?
score, because it shows what the variable holds. x tells the reader nothing.
Better name than h for a height measured in feet?
height_in_feet: meaningful, and in snake case.
What can happen if programmers don't use meaningful names?
The code may become difficult to maintain or fix, and other programmers may not be able to understand it.
Breaking a rule vs breaking a convention: what's the difference?
Break a rule and the name isn't allowed. Break the convention and it's allowed, but not a suitable identifier.

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 posted

More OCR GCSE Computer Science topics

See the full OCR Computer Science curriculum →

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.