Variables, Parameters, Arguments

From NovaOrdis Knowledge Base
Revision as of 20:15, 17 August 2023 by Ovidiu (talk | contribs) (→‎Parameter)
Jump to navigation Jump to search

Internal

Variable

Variables are names associated with memory locations that store values. In most programming languages, the values stored in memory have a formal type associated with them. Depending on the static or dynamic typing nature of the language, variables may or may not allow the modification their type throughout the execution of the program. A useful mental representation of a variable is a sticky note that can be attached to an object, and then re-attached to a different object. Depending on the language, the second object may or may not be of the same type. Variables and identifiers are equivalent.

Variables in various programming languages:

Identifier

Parameter

A parameter is a variable name used in a function definition. Each parameter translates to a variable private to the function. The parameters are handles for arguments for a particular function invocation. Function parameters in various languages:

Argument

Function arguments in various languages:

Discussion

This terminology applies to Java method invocations, Python method invocations and even Java generics, where the ordinary parameters and variables are replaced with type parameters (type variables), and the arguments are replaced with type arguments.