Functions and Procedural Abstraction
Functions package computations behind callable interfaces. A function definition specifies a name, parameters, and a body.
Summary
Functions package computations behind callable interfaces. A function definition specifies a name, parameters, and a body. Procedural abstraction allows callers to rely on a function's contract rather than its implementation. Implementations can change without requiring changes to callers, provided the contract remains satisfied.
A contract describes expected inputs, preconditions, outputs, postconditions, and observable side effects. Calling a function transfers control to its body; returning transfers control back and may deliver a result. Local variables normally have scope within the function or an enclosing block.
| Distinction | First concept | Second concept |
|---|---|---|
| Parameter vs. argument | Name declared in a function definition | Value or expression supplied at a call |
| Precondition vs. postcondition | Must hold before execution | Guaranteed after normal completion when preconditions hold |
| Return value vs. side effect | Result delivered to the caller | Observable state change or interaction |
A pure function produces the same result for the same inputs and has no observable side effects. Cohesive functions concentrate on one responsibility. Reusable functions centralize shared behavior, reducing duplication and inconsistent fixes. Explicit inputs and limited side effects support independent testing and debugging.
Common Misconceptions: Parameters and arguments are not interchangeable terms. Returning a value does not by itself make a function pure. Procedural abstraction does not require callers to understand the function's internal algorithm.
🧠 Key Concepts
- Procedural abstraction
- Parameters and arguments
- Function contracts
- Preconditions and postconditions
- Return values
- Local scope
- Pure functions
- Cohesion
🧠 Quick Check
See what you remember from the summary.
Which best describes procedural abstraction?
🧠 Flashcards Preview
Tap a card to reveal the definition.
Ready to quiz yourself?
Test what you remember with a full practice quiz on this note. Create a free account and start in seconds.
Full Notes
Read the original note content before deciding whether to save or study from it.
Functions and Procedural Abstraction
📘 Overview Functions package a defined computation behind a callable interface. Procedural abstraction lets a caller use that computation through its contract without depending on its implementation.
🧠 Key Idea A function separates what a computation promises from how it is performed. Callers rely on its interface and contract, allowing implementation details to change without changing correct calling code.
⚔️ Core Details: - A function definition specifies a name, parameters, and a body containing the computation. - Parameters are names declared by a function; arguments are the values or expressions supplied when calling it. - A function contract states the expected inputs, preconditions, outputs, postconditions, and any observable side effects. - A function call transfers control to the function body; a return transfers control back and may supply a result. - Local variables normally have scope within the function or an enclosing block, rather than throughout the program. - A pure function produces the same result for the same inputs and causes no observable side effects.
🎯 Why It Matters: - Well-defined interfaces allow implementations to be replaced without requiring changes to callers that obey the contract. - Breaking a program into cohesive functions reduces the amount of code that must be understood at once. - Reusable functions centralize shared behavior, reducing duplicated logic and inconsistent fixes. - Explicit inputs and limited side effects make functions easier to test independently and debug.
🧠 Quick Recall: - Procedural abstraction - Using a named operation through its contract without relying on its internal implementation. - Parameter versus argument - A parameter appears in a function definition; an argument is supplied at a call. - Return value versus side effect - A return value is a result delivered to the caller; a side effect changes observable state or performs an observable interaction. - Precondition versus postcondition - A precondition must hold before execution; a postcondition is guaranteed after normal completion when preconditions hold. - Cohesion - The degree to which a function's operations contribute to one focused responsibility.
More ways to study when you copy this note
Copy this note into your library to unlock focused practice sessions and long-term review.
Answer all questions first, then see feedback at the end — the way real exams work.
Focuses each session on what you got wrong, not what you already know.
Full timed exam with all questions, no pausing, and results at the end. Built for board exam prep.
Part of 🗄️ BS Information Systems — 1st Year
Browse this Review Set →More Computer Science notes
See all →More in Programming Fundamentals
See all →More from NoteLib
Browse NoteLib's public notes →Copy this note to your library and get the full Study Pack instantly — summary, key concepts, and practice quiz included.