Function
Also known as: procedure, subroutine, method, def
A named, reusable block of code that performs a specific task and can optionally accept inputs and return a result. Functions are the primary abstraction in programming; nearly all software is organized around them.
๐ก 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
๐ฏ Why It Matters
Functions are the primary abstraction in programming; nearly all software is organized around them.
โ ๏ธ Common Confusion
Defining a function doesn't run it โ you must call it. Parameters (defined) differ from arguments (passed in).
Related Concepts
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.
Go Deeper
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 and return a result.
Why is Function important?
Functions are the primary abstraction in programming; nearly all software is organized around them.
What do students usually get wrong about Function?
Defining a function doesn't run it โ you must call it. Parameters (defined) differ from arguments (passed in).
What should I learn before Function?
Before studying Function, you should understand: function programming, return values, modular design.