← Back to catalogue
Research draft

subroutine

vr.tr.subroutine · XCT.QLT

Let an agent explain subroutines and their variants across languages, help design, document and test functions, and explain calling conventions and recursion.

Thing Registry Cross-cutting context

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

language construct

is a kind of - category

control flow

is written in - activity

computer programming

is related to - call hierarchies

hierarchy

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

recursive functionfactory methodstatic methodSPARQL functionshell functiongeneric methodbuiltin functioninterrupt handlerintrinsic functionfunctions in JavaScriptprogram modulewrapper functionaggregate functionnull functionhelper functionstored procedurefunctionalwindow function

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.

  1. What does this language call subroutines, and how do functions, procedures and methods differ in it? definition
  2. What are static, generic and factory methods? definition

Mechanics

Calls and returns.

Mechanics

Mechanics.

  1. How are arguments passed and values returned in this language, and what is the calling convention? definition
  2. What happens on the call stack? definition
Design Writing good functions.

Interfaces.

Interface

Clear interfaces.

Interface

Interfaces.

  1. How should this function be named, parameterised and documented? action
  2. Should it be pure or have side effects? boundary

Size

Scope and size.

Size

Scope.

  1. Is this function doing too much, and how should it be split? boundary
  2. Which refactoring applies? action
Recursion Recursive functions.

Base cases.

Write

Writing recursion.

Write

Recursion.

  1. How can this problem be solved recursively, with a correct base case? action
  2. Is iteration clearer or more efficient? boundary

Limits

Recursion limits.

Limits

Limits.

  1. What stack depth limits apply, and does the language optimise tail calls? provenance
  2. How can deep recursion be avoided? action
Quality Testing and documentation.

Reliability.

Test

Testing functions.

Test

Testing.

  1. How should this function be unit tested, including edge cases? action
  2. Which testing framework applies? provenance

Document

Documenting.

Document

Documentation.

  1. How should the function be documented for callers? action
  2. 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?