Lably
Skip to content

Function (computer programming)

Sequence of program instructions invokable by other software

  • 33 min read
  • 6 chapters
  • 6 labs on Lably

Learn it on Lably

Callable units provide a powerful programming tool. The primary purpose is to enable the decomposition of a large and/or complicated problem into chunks that have relatively low cognitive load. These smaller, less complicated chunks (callable units) can become conceptually independent of the larger problem, taking on meaningful names of their own and potentially becoming useful to other unrelated problems through reusability. Judicious application can reduce the cost of developing and maintaining software through modularity and reusability, while increasing quality and reliability.

Callable units are present at multiple levels of abstraction in the programming environment. For example, a programmer may write a function in source code that is compiled to machine code that implements similar semantics. There is a callable unit in the source code and an associated one in the machine code, but they are different kinds of callable units—with different implications and features.

Terminology

Some programming languages, such as COBOL and BASIC, make a distinction between functions that return a value (typically called "functions") and those that do not (typically called "subprogram", "subroutine", or "procedure"); some, such as C, C++, and Rust, only use the term "function" irrespective of whether they return a value or not; others, such as ALGOL 60 and PL/I, only use the word procedure. Some object-oriented languages, such as Java and C#, refer to functions inside classes as "methods".

Sign in to keep reading

5 more chapters are free with a Lably account.

More in Computing and communication