subroutine
Let an agent explain subroutines and their variants across languages, help design, document and test functions, and explain calling conventions and recursion.
Research draft, second pass
A second pass drafted this model: the structure a model of this thing needs, and what is known about it in the world. The line under this one says how the second half was obtained - researched against sources, or recalled without web access, in which case nothing here was read anywhere and every claim is a lead to verify. Unreviewed either way.
written by Claude from model knowledge without web access - no source was read, every claim is a lead to verify
Researched by: Claude
Purpose and description
Let an agent explain subroutines and their variants across languages, help design, document and test functions, and explain calling conventions and recursion.
A named sequence of instructions in a program that performs a task and can be called from other parts of the program, known variously as a function, procedure, method or routine, taking arguments and often returning values, including recursive functions, static and generic methods, shell functions and functions in query languages; subroutines are the basic unit of code reuse and structure.
What it is for: Structuring and reusing code.
It can be explain functions, procedures and methods; design clear function interfaces; explain recursion and calling conventions; test and document functions.
Distinguishing features
Named and callable
Parameters and returns
Reusable
Language-specific forms
What it looks like
Not physical; blocks of code with names and parameters.
How it is recognised
Named callable block
Parameters and return values
A macro expands text rather than being called
Related models
is a kind of - category
is a kind of - category
is written in - activity
is related to - call hierarchies
In practice
Families and kinds
functions and procedures
methods including static and generic methods
recursive functions
shell and script functions
functions in query and domain languages
Standards and regulation
Language specifications
Coding standards and style guides
Failure modes and hazards
Side effects and hidden state
Unbounded recursion
Poorly defined interfaces
Also called
Where this came from
wikidata · CC0 1.0
Drafted structure
Bundle to layer to finding to question, as the second pass will find it: 4 bundles · 8 layers · 8 findings · 16 questions.
Concept What a subroutine is.
Terms across languages.
Terms
Function, procedure, method.
Terms
Terms.
- What does this language call subroutines, and how do functions, procedures and methods differ in it? definition
- What are static, generic and factory methods? definition
Mechanics
Calls and returns.
Mechanics
Mechanics.
- How are arguments passed and values returned in this language, and what is the calling convention? definition
- What happens on the call stack? definition
Design Writing good functions.
Interfaces.
Interface
Clear interfaces.
Interface
Interfaces.
- How should this function be named, parameterised and documented? action
- Should it be pure or have side effects? boundary
Size
Scope and size.
Size
Scope.
- Is this function doing too much, and how should it be split? boundary
- Which refactoring applies? action
Recursion Recursive functions.
Base cases.
Write
Writing recursion.
Write
Recursion.
- How can this problem be solved recursively, with a correct base case? action
- Is iteration clearer or more efficient? boundary
Limits
Recursion limits.
Limits
Limits.
- What stack depth limits apply, and does the language optimise tail calls? provenance
- How can deep recursion be avoided? action
Quality Testing and documentation.
Reliability.
Test
Testing functions.
Test
Testing.
- How should this function be unit tested, including edge cases? action
- Which testing framework applies? provenance
Document
Documenting.
Document
Documentation.
- How should the function be documented for callers? action
- Which documentation conventions apply in this language? provenance
What the second pass must settle
- Should methods be a separate entry?
- How should language references be linked?
- How should testing practices be linked?