Skip to content
Definition
Sub-procedures are the building blocks of a program - small, well-defined tasks that can be reused and tested independently. Identifying and creating these is essential for efficient, modular program design.

Benefits of Sub-Procedures

Key Point
AdvantagePractical benefit
ModularityComponents can be built independently
ReusabilitySame routine can be reused across features
TestabilityEach routine can be unit tested in isolation
MaintainabilityFix once in one procedure, benefit everywhere
ReadabilitySmaller named routines make code easier to follow
Team collaborationDifferent developers can own different procedures

The Interface of a Sub-Procedure

Definition
The interface of a sub-procedure is its name, the parameters it must be passed and the value it returns. It is all that another programmer needs to know in order to call it.
Sub-procedureParameters (inputs)Returns (output)
getISBNbookTitleThe ISBN of the matching book
checkAvailabilityISBNTrue if a copy is in stock, otherwise false
confirmReservationuserID, ISBN, locationNothing: it is a procedure that saves the reservation

Agreeing each interface before any code is written lets different programmers write and test their sub-procedures separately, because each one knows what the others will supply and expect.

Worked Example
Worked Example: Library System Sub-Procedures
pseudocode
// Sub-procedure 1: Get user name
function getName():
    if isSignedIn() then
        return currentUser.name
    else
        return null
    end if
end function

// Sub-procedure 2: Get book ISBN
function getISBN(bookTitle):
    book = database.findBook(bookTitle)
    return book.ISBN
end function

// Sub-procedure 3: Check availability
function checkAvailability(ISBN):
    return database.getStock(ISBN) > 0
end function

// Sub-procedure 4: Select location
function selectLocation():
    return displayLocationMenu()
end function

// Sub-procedure 5: Confirm reservation
procedure confirmReservation(userID, ISBN, location):
    database.createReservation(userID, ISBN, location)
end procedure

// Main procedure combining all sub-procedures
procedure main():
    name = getName()
    ISBN = getISBN(input("Book title: "))
    if checkAvailability(ISBN) then
        location = selectLocation()
        confirmReservation(name, ISBN, location)
    end if
end procedure
Each sub-procedure can be developed, tested, and debugged independently before integration.
Exam Tip
Exam Tips for Thinking Procedurally:
• Be able to decompose a problem into components
• Identify appropriate sub-procedures for given scenarios
• Understand the order/sequence of steps
• Recognise dependencies between procedures
• Explain benefits of decomposition (modularity, testing, teamwork)
• Write pseudocode for sub-procedures with clear inputs/outputs