Why Layout Matters
Edexcel Paper 2 marks programs that other people can follow. Use indentation for blocks, white space around operators, and meaningful identifiers such as total_score instead of x.
Add short comments where the intent is not obvious from the names. A comment should say why, not repeat the code. Layout, names and comments do not change the answer the CPU computes, but they change how fast a human can find a logic error.
A meaningful identifier is a name that
{"answers": {"A": "Describes what the variable or subprogram is for", "B": "Is always a single letter", "C": "Must be written in CAPITALS", "D": "Is ignored by the interpreter"}, "question_text": "A meaningful identifier is a name that", "correct_answer": "A"}
Comments versus Identifiers
Identifier
minutes_left = 10 already tells you the unit. You do not need a comment that says βthis is minutesβ.Comment
Use a comment for a non-obvious choice, such as why a loop stops at 59 rather than 60. If you rename a variable, update comments that mention the old name.
Use [[indentation]] for blocks and [[meaningful]] names such as total_score instead of x.
{"cloze_text": "Use [[indentation]] for blocks and [[meaningful]] names such as total_score instead of x."}
{"keyword": "meaningful identifier", "definition": "A variable, constant or subprogram name that describes its purpose"}
Question Type: fill in the blanks
{"paragraph": "Comments should explain [[why]] something is done, not copy the [[code]] line by line."}
{"paragraph": "Comments should explain [[why]] something is done, not copy the [[code]] line by line."}
Question Type: short answer
{"answer": "Indentation/white space, meaningful identifiers, or comments.", "rubric": {"0": "Incorrect or no response", "1": "Partial credit", "2": "Indentation/white space, meaningful identifiers, or comments."}, "question": "Name two techniques that make a program easier to maintain."}
{"answer": "Indentation/white space, meaningful identifiers, or comments.", "rubric": {"0": "Incorrect or no response", "1": "Partial credit", "2": "Indentation/white space, meaningful identifiers, or comments."}, "question": "Name two techniques that make a program easier to maintain."}
Complete! Ready to test your knowledge?
Readable programs
- Why Layout Matters
- Comments versus Identifiers