- Home
- /
- Computational Thinking
- /
- Programming Fundamentals
- /
- Function
Function
Also known as: procedure, subroutine, method, def
Grade 6-8
View on concept mapA named, reusable block of code that performs a specific task and can optionally accept inputs (parameters) and return a result. Functions are the primary abstraction in programming; nearly all software is organized around them.
Definition
A named, reusable block of code that performs a specific task and can optionally accept inputs (parameters) and return a result. Functions allow you to organize code into logical units, write a solution once, and invoke it from anywhere in the program.
π‘ Intuition
Like a recipe: you name it, write it once, and call it whenever you need it.
π― Core Idea
Functions break programs into manageable pieces, enable reuse, and reduce repetition.
Example
Formula
π Why It Matters
Functions are the primary abstraction in programming; nearly all software is organized around them. They enable code reuse, improve readability, simplify testing, and allow teams to divide work by assigning different functions to different developers.
π Hint When Stuck
When creating a function, give it a descriptive name that tells what it does. Define parameters for any data it needs from the caller. Use return to send a result back. Keep each function focused on a single taskβif it does too many things, split it into smaller functions.
Formal View
π§ Common Stuck Point
Defining a function doesn't run it β you must call it. Parameters (defined) differ from arguments (passed in).
β οΈ Common Mistakes
- Defining a function but never calling it, then wondering why nothing happens
- Writing functions that are too long and do too many things, making them hard to test and reuse
- Confusing parameters (placeholders in the definition) with arguments (actual values passed at the call site)
Common Mistakes Guides
Frequently Asked Questions
What is Function in CS Thinking?
A named, reusable block of code that performs a specific task and can optionally accept inputs (parameters) and return a result. Functions allow you to organize code into logical units, write a solution once, and invoke it from anywhere in the program.
What is the Function formula?
def function_name(parameters): β body β return value
When do you use Function?
When creating a function, give it a descriptive name that tells what it does. Define parameters for any data it needs from the caller. Use return to send a result back. Keep each function focused on a single taskβif it does too many things, split it into smaller functions.
Prerequisites
Next Steps
How Function Connects to Other Ideas
To understand function, you should first be comfortable with function programming, return values and modular design. Once you have a solid grasp of function, you can move on to recursion and event handler.