Developing Procedures (College Board AP® Computer Science Principles): Study Guide
Procedural abstraction
What is procedural abstraction?
Procedural abstraction is the practice of defining a named process that hides its implementation details from the rest of the program
A program can be subdivided into smaller modular sub-problems, each handled by a separate procedure
Each procedure performs one specific task, making the overall program easier to design, test, and understand
Benefits of procedural abstraction
Shared feature extraction: if the same code appears in multiple places, it can be moved into a procedure and called wherever needed
Parameter generalization: using parameters makes a procedure reusable with different inputs, rather than writing separate code for each case
Improved readability: procedure names describe what the code does, making the program easier to follow at a glance
Benefit | What it means | Example |
|---|---|---|
Shared feature extraction | Reuse one procedure instead of repeating code | A |
Parameter generalization | Parameters allow the same procedure to handle different inputs | A |
Improved readability | Procedure names describe the task |
|
Maintenance and modularity
Internal change isolation means that updating a procedure's logic only needs to happen in one place, regardless of how many times it is called
Each procedure can be tested and debugged independently from the rest of the program
If a bug is found in a procedure, fixing the definition fixes it everywhere it is called
Procedure definition and returns
Procedures are defined using the
PROCEDUREkeyword with optional parameters, and can optionally return a value usingRETURN; see Procedure Syntax and Parameters for full details and worked examplesThe key point for abstraction is that the calling code does not need to know how a procedure works internally, only what it is named, what inputs it takes, and what it returns
Examiner Tips and Tricks
In exam questions about procedural abstraction, look for repeated code sections that could be replaced with a single procedure call — this is the shared feature extraction principle in action. Remember that the calling code does not need to know how a procedure works internally — only its name, inputs, and return value matter to the caller.
For the CPT, procedural abstraction is a scored element; your procedure must use its parameter meaningfully within the body and your written response must explain how the procedure contributes to the program's overall functionality.
Worked Example
The following code appears three times in a student's program, each time with a different value of radius:
area ← 3.14 * radius * radius
DISPLAY(area)
Which change best demonstrates procedural abstraction?
(A) Move the repeated code into a loop
(B) Replace the repeated code with a procedure that takes radius as a parameter
(C) Store the result in a different variable each time
(D) Add a comment above each repeated section explaining what it does
[1]
Answer:
(B) Replace the repeated code with a procedure that takes radius as a parameter [1 mark]
Replacing repeated code with a parameterized procedure applies both shared feature extraction and parameter generalization; a single
calculateArea(radius)procedure replaces three identical code blocks and works for any value ofradius
Unlock more, it's free!
Was this revision note helpful?