Parameter (computer science)
Named inputs used by routines and programs to receive values that control execution. Covers formal vs actual parameters, passing methods, defaults, typing, scope, and uses in APIs and interfaces.
In computer science, a parameter is a named placeholder in a routine, function, method or process that receives a value when that routine is invoked. Parameters let code be written generically: the same body of a subroutine can operate on different inputs without modification. When a routine call supplies actual data to those placeholders, the supplied items are commonly called arguments; the distinction between a formal parameter (the name in the routine definition) and an actual argument (the value passed at call time) is central to understanding how calls behave. See also subroutine for the surrounding concept.
Characteristics and role
Parameters appear in a routine's signature and define the number, order and expected kinds of values that callers may provide. They are associated with names, types or constraints (in typed languages), and default values in many languages. Parameters determine how data flows into a routine and thus influence correctness, maintainability and the surface contract of an API or library. They also affect performance and memory use because the method of passing values can copy data, share references, or move ownership.
Common parameter passing methods
- Pass-by-value: the callee receives a copy of the argument; modifications do not affect the caller.
- Pass-by-reference: the callee receives access to the same storage, so changes are visible to the caller.
- Pass-by-sharing / object reference: languages that use references pass a handle to an object but not the primitive value, blending ideas of value and reference semantics.
- Variadic and keyword parameters: allow an arbitrary number of arguments or arguments specified by name rather than position.
Different languages implement these mechanisms in different ways; for example, some provide explicit reference types, others use pointers, and some rely on a uniform object model. Default values, named/keyword arguments, and strict type annotations are features that shape how parameters are declared and used.
Uses, examples and notable distinctions
Parameters are used wherever behavior must be parameterized: mathematical functions, sorting routines (a comparator parameter), configuration APIs, command-line options, and callbacks. In API design, choosing clear parameter names, sensible defaults and minimal required parameters improves usability. Distinctions to watch are parameter mutability (can the routine alter the argument’s state), lifetime (parameters are typically local to a call's activation record), and visibility (most parameters are local, though some languages allow pattern-matching or destructuring in declarations).
Historically, parameter passing has evolved with programming language design to balance safety, expressiveness and efficiency. From early procedural languages to modern multi-paradigm systems, parameters remain a fundamental device for abstraction and modularity in software engineering.
Related articles
Author
AlegsaOnline.com Parameter (computer science) Leandro Alegsa
URL: https://en.alegsaonline.com/art/74547
Sources
- bbc.co.uk : bbc.co.uk
- whatis.techtarget.com : "What is parameter? - Definition from WhatIs.com"