AP COMPUTER SCIENCE PRINCIPLES • ALGORITHMS AND PROGRAMMING

Developing Procedures

Master the art of writing reusable, parameterized procedures to manage complexity in programs.

Historical Context & Motivation

The idea of breaking a complex program into smaller, self-contained units is arguably the single most transformative insight in the history of software engineering. In the earliest days of computing, programmers wrote monolithic sequences of machine instructions where every action was enumerated line by line, making programs extremely difficult to read, debug, and extend. As programs grew in size—from hundreds of instructions to thousands and eventually millions—the need for procedural abstraction became unavoidable. A procedure (also called a function, subroutine, or method depending on the language) encapsulates a sequence of instructions under a single name, allowing programmers to invoke that sequence repeatedly without rewriting it. This concept did not emerge overnight; it evolved through decades of programming language design and engineering practice.

1949
Subroutines in EDSAC
Maurice Wilkes and David Wheeler at Cambridge developed the concept of subroutines for the EDSAC computer—reusable blocks of machine code stored in a library and called by name, eliminating redundant code.
1958
FORTRAN & LISP Functions
FORTRAN introduced FUNCTION and SUBROUTINE declarations, while LISP elevated functions to first-class citizens, enabling higher-order programming and recursion.
1968
Structured Programming Movement
Edsger Dijkstra's landmark letter "Go To Statement Considered Harmful" catalyzed the structured programming movement, advocating procedures and control structures over arbitrary jumps.
1972
C Language Standardizes Functions
Dennis Ritchie's C language made function definitions with parameters and return values a standard feature, influencing virtually every language that followed.
2007–present
AP CSP & Modern Abstraction
The AP Computer Science Principles framework formalized procedural abstraction as a core computational thinking skill, recognizing that developing procedures is fundamental to managing program complexity.

The central question that procedures address is deceptively simple: How can we write code once and use it in many places, adapting its behavior through inputs? This question leads directly to the concepts of parameters, return values, and the separation between a procedure's interface (what it does) and its implementation (how it does it). Mastering these ideas is essential for the AP CSP exam and for computational thinking in any discipline.

Core Principles & Definitions

Before diving into implementation details, it is critical to establish a precise vocabulary. The AP CSP exam uses specific terminology drawn from the College Board's pseudocode reference sheet, and understanding these terms will help you navigate both multiple-choice and Create Performance Task questions with confidence. The foundational ideas below form the conceptual bedrock of developing procedures.

1

Procedure (Function)

A named group of programming instructions that may take parameters and may return a value. Once defined, it can be called (invoked) by name wherever its behavior is needed.
2

Parameter vs. Argument

A parameter is a variable in a procedure definition that acts as a placeholder. An argument is the actual value passed to the procedure when it is called.
3

Return Value

A procedure may compute and send back a result using a RETURN statement. The calling code can store or use this result. Procedures without a return value perform actions (side effects) instead.
4

Procedural Abstraction

The process of naming a block of code so that a programmer can use it without knowing its internal details. This reduces complexity by allowing you to think about what a procedure does rather than how it does it.
5

Modularity

Breaking a program into independent, testable procedures makes code easier to debug, maintain, and collaborate on. Each procedure has a single, well-defined responsibility.
KEY TAKEAWAY
Think of a procedure like a recipe card in a restaurant kitchen. The recipe's name is how the waiter orders it, the parameters are the customizations ("extra cheese," "no onions"), and the return value is the finished dish. The waiter doesn't need to know every step of the cooking process—only the name and what inputs to provide. That separation of 'what' from 'how' is procedural abstraction in action.

Visual Explanation: Anatomy of a Procedure

The diagram below illustrates the complete lifecycle of a procedure call. On the left, you see the procedure definition—where the procedure's name, parameters, and body are declared. On the right, you see procedure calls from the main program, each passing different arguments. The arrows trace the flow of data: arguments flow in, the body executes, and a return value flows back to the caller.

The procedure calculateArea is defined once (violet box, left) with parameters width and height. It is called twice (cyan and amber boxes, right) with different arguments. Each call sends arguments in (cyan arrows) and receives a return value back (green arrows).

Notice how the procedure body is written only once, yet it produces different results depending on the arguments supplied. This is the essential power of generalization through parameters. Without parameters, you would need a separate block of code for every unique pair of dimensions—an approach that is neither scalable nor maintainable. The AP CSP pseudocode uses the syntax PROCEDURE name (param1, param2) for definitions and simply name(arg1, arg2) for calls. Understanding this flow—definition, call, argument binding, execution, return—is essential for tracing code on the exam.

How Procedures Work: Pseudocode Deep Dive

The AP CSP exam reference sheet provides two forms of procedure definition. Understanding both is non-negotiable for the exam. The first form defines a procedure that performs actions but does not return a value—it produces side effects such as displaying output or modifying a list. The second form defines a procedure that computes and returns a result to the caller.

Procedure Without a Return Value

DEFINITION (NO RETURN)
PROCEDURE procName (param1, param2, …) { <block of statements> }
procName — the identifier used to call this procedure. param1, param2, … — zero or more parameters that act as local variables initialized to the caller's arguments. The body executes sequentially and control returns to the caller when the closing brace is reached.

Procedure With a Return Value

DEFINITION (WITH RETURN)
PROCEDURE procName (param1, param2, …) { <block of statements> RETURN (expression) }
The RETURN statement sends the evaluated expression back to the point where the procedure was called. After RETURN executes, no further statements in the procedure body run.

Calling a Procedure

PROCEDURE CALL
result ← procName (arg1, arg2, …)
Arguments are matched to parameters by position: the first argument binds to the first parameter, the second to the second, and so on. If the procedure returns a value, the assignment operator stores it. If the procedure does not return a value, the call is a standalone statement.
📝 EXAM TIP
On the AP CSP exam, you will often be asked to trace procedure calls. To do this systematically: (1) identify the arguments, (2) substitute them for the parameters in the body, (3) execute the body line by line, and (4) note the return value. Keeping a small table of variable values on scratch paper is extremely effective.

An important distinction that the AP CSP framework emphasizes is the difference between procedures that return values and procedures that produce side effects. A procedure like DISPLAY("Hello") outputs text to the screen but does not send a value back to the caller. In contrast, a procedure like calculateArea(5, 10) computes and returns 50. Some procedures do both—they perform an action and return a value—but conceptually separating these two roles helps you write cleaner, more modular code.

Design Patterns for Developing Procedures

When developing a procedure, experienced programmers follow well-established design patterns. The AP CSP exam tests your ability to recognize when and why a procedure should be created, how to choose appropriate parameters, and how procedures can call other procedures. The diagram below categorizes the most common patterns you will encounter.

Five common patterns for developing procedures. Pattern 1 is the simplest (no inputs or outputs). Patterns 2 through 5 illustrate increasing sophistication: parameterized computation, composition of procedures, list iteration, and conditional branching within a procedure body.

Pattern 3 deserves special attention because it demonstrates a principle the AP CSP framework emphasizes heavily: procedures can call other procedures. In the volume example, the programmer reuses an existing area procedure rather than re-implementing the multiplication logic. This layered approach—building complex behavior from simpler, tested pieces—is the heart of managing complexity in large programs. On the Create Performance Task, describing how one of your procedures calls another is an excellent way to demonstrate abstraction.

💡 WHEN TO CREATE A PROCEDURE
A good rule of thumb: if you find yourself writing the same (or nearly the same) block of code in two or more places, extract it into a procedure. Additionally, if a block of code performs a logically distinct task—even if used only once—wrapping it in a named procedure improves readability and testability.

Worked Example: Building a Grade Calculator

Let us work through a complete example that mirrors the type of problem you might encounter on the AP CSP exam. We will develop two procedures: one that computes the average of a list of scores, and one that converts a numeric average into a letter grade. Then we will trace a call to demonstrate the full flow.

Grade Calculator with Two Procedures
1
Step 1 — Define the average procedureWe need a procedure that accepts a list of numbers and returns their average. Using AP CSP pseudocode: PROCEDURE average(scores) { sum ← 0 FOR EACH s IN scores { sum ← sum + s } RETURN (sum / LENGTH(scores)) } The parameter scores is a list. The procedure iterates through it, accumulates a sum, and returns the sum divided by the list's length.
2
Step 2 — Define the letter grade procedureNow we create a procedure that takes a numeric grade and returns the corresponding letter: PROCEDURE letterGrade(numGrade) { IF (numGrade ≥ 90) { RETURN ("A") } ELSE IF (numGrade ≥ 80) { RETURN ("B") } ELSE IF (numGrade ≥ 70) { RETURN ("C") } ELSE { RETURN ("F") } }
3
Step 3 — Compose the procedures in the main programIn the main program, we call average and pass its return value directly into letterGrade: myScores ← [88, 92, 76, 95, 84] avg ← average(myScores) grade ← letterGrade(avg) DISPLAY(grade)
4
Step 4 — Trace the executionFirst, average([88, 92, 76, 95, 84]) is called. The loop computes sum = 88 + 92 + 76 + 95 + 84 = 435. The return value is 435 / 5 = 87. Next, letterGrade(87) is called. Since 87 ≥ 80 (but not ≥ 90), the procedure returns "B". Finally, DISPLAY outputs "B".
avg = 87, grade = "B", output: B
5
Step 5 — Identify the abstractionThis example demonstrates procedural abstraction at two levels. The average procedure hides the loop-and-divide logic. The letterGrade procedure hides the conditional thresholds. The main program reads almost like English: 'compute the average, then get the letter grade, then display it.' If the grading scale changes, only letterGrade needs modification—the rest of the program remains untouched.

Benefits, Tradeoffs, and Common Pitfalls

Developing procedures introduces clear benefits, but it also comes with design tradeoffs that you should be able to articulate, especially on free-response and Create Performance Task prompts. The table below organizes the key considerations.

Benefits and tradeoffs of developing procedures
BenefitTradeoff / PitfallExam Relevance
Code reuse: write once, call many timesOver-generalizing a procedure with too many parameters can make it confusing to call correctlyMCQ: identify which procedure eliminates repeated code
Readability: meaningful names convey intentPoorly named procedures (e.g., doStuff()) harm readability instead of helping itCreate Task: descriptive naming is explicitly assessed
Debugging: isolate and fix one procedure without breaking othersIf a procedure modifies global variables (side effects), bugs may propagate unpredictablyMCQ: trace bugs in procedure calls
Collaboration: team members work on separate proceduresRequires clear communication about parameter types and expected return valuesCreate Task: collaboration reflection question
Abstraction: hide implementation detailsStudents sometimes confuse parameters with arguments, or forget to use RETURNMCQ/FRQ: distinguish parameter from argument
KEY TAKEAWAY
Think of procedures like power tools in a workshop. A well-designed drill (procedure) has clearly labeled settings (parameters), accepts standard bits (arguments), and produces predictable holes (return values). You don't need to understand the motor's internal wiring to use it effectively. However, if you label the drill 'thing1' and give it fifteen unlabeled settings, nobody—including you—will use it correctly. Good procedure design balances generality with simplicity.

Connection to Advanced Programming Concepts

The procedures you learn in AP CSP are the foundation upon which more advanced programming paradigms are built. Understanding how CSP-level procedural abstraction connects to concepts you may encounter in AP Computer Science A, college-level courses, or industry practice will deepen your appreciation for why the exam emphasizes this topic so heavily.

How AP CSP procedure concepts extend to advanced topics
AP CSP ConceptAdvanced ExtensionKey Difference
Procedure with parametersMethods in OOP — procedures attached to objectsMethods operate on an object's internal state via this or self
Calling a procedure from another procedureRecursion — a procedure calling itselfRequires a base case to prevent infinite execution
RETURN a single valueReturn complex types — lists, objects, tuplesFunctions can return structured data, not just single numbers or strings
Procedural abstractionAPIs and libraries — thousands of pre-built proceduresYou use procedures written by others without seeing their source code
Parameters as placeholdersHigher-order functions — passing procedures as parametersThe parameter itself is a procedure (e.g., map(square, myList))

Recognizing these connections is more than academic trivia. When you write procedures in your Create Performance Task, you are practicing the same skill that professional software engineers use daily: decomposing a problem into named, reusable units of behavior. Whether those units are simple procedures, methods in a Java class, or endpoints in a web API, the underlying principle of separating interface from implementation remains the same.

Practice Problems

1
A programmer writes a procedure PROCEDURE double(x) that contains the statement RETURN (x × 2). Which of the following best describes the role of x in the procedure definition?
2
Consider the following procedures:PROCEDURE add(a, b) { RETURN (a + b) }PROCEDURE multiply(a, b) { RETURN (a × b) }What is the value of result after the following statement executes?result ← multiply(add(3, 2), 4)
3
A student writes the following procedure: PROCEDURE mystery(n) { result ← 1 REPEAT n TIMES { result ← result × 2 } RETURN (result) } Select two true statements about this procedure.
PROBLEM 4APPLIED
A school wants to determine whether a student qualifies for the honor roll. A student qualifies if their average score across all courses is at least 85 and no individual score is below 70. (a) Write a procedure isHonorRoll(scores) in AP CSP pseudocode that takes a list of scores and returns true or false. (b) Identify one way this procedure demonstrates procedural abstraction. (c) Give an example input list where the student has an average ≥ 85 but does not qualify for honor roll.
PROBLEM 5CRITICAL THINKING
A programmer is developing a fitness tracking application. The app has three existing procedures: • PROCEDURE totalSteps(dailyStepList) — returns the sum of all step counts in the list. • PROCEDURE avgSteps(dailyStepList) — returns the average daily step count. • PROCEDURE daysAboveGoal(dailyStepList, goal) — returns the count of days where steps exceeded the goal. The programmer needs a new procedure weeklyReport(dailyStepList, goal) that displays a summary including the total steps, average steps, and number of days the goal was met. (a) Write the weeklyReport procedure in AP CSP pseudocode. Your procedure must call at least two of the existing procedures. (b) Explain how your procedure demonstrates procedural abstraction. (c) The programmer wants to add a feature where the report also shows whether the user achieved a "streak" of 3 or more consecutive days above the goal. Describe, in detail, how you would develop a new procedure hasStreak(dailyStepList, goal, streakLength) and integrate it into weeklyReport. Include pseudocode for hasStreak. (d) Discuss one benefit and one potential challenge of having weeklyReport depend on multiple smaller procedures.

Summary

A procedure is a named, reusable block of code that may accept parameters (placeholders defined in the procedure header) and may return a value to the caller. When a procedure is called, the caller passes arguments (actual values) that are matched to parameters by position. The AP CSP pseudocode provides two forms: procedures with RETURN statements for computing results, and procedures without RETURN for performing side effects like displaying output.

The central benefit of developing procedures is procedural abstraction: hiding implementation details behind a meaningful name so that programmers can reason about what a procedure does without worrying about how it does it. This enables code reuse, improves readability, simplifies debugging, and supports collaboration. Procedures can call other procedures, enabling layered abstraction where complex behavior is built from simpler, well-tested components. For the AP CSP exam, practice tracing procedure calls with argument substitution, and for the Create Performance Task, be prepared to explain how your procedures manage complexity and generalize behavior through parameters.

Varsity Tutors • AP Computer Science Principles • Developing Procedures