Variables, Parameters, Arguments: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 27: Line 27:
* [[Java_Language#Method_Parameter|Java method parameters]]
* [[Java_Language#Method_Parameter|Java method parameters]]
* [[Python_Language_Functions#Function_Parameters|Python function parameters]]
* [[Python_Language_Functions#Function_Parameters|Python function parameters]]
* [[Go_Functions#Parameters|Go function parameters]]
* [[Bash_Parameters_and_Variables#Parameters_and_Variables|Bash variables and parameters]]
* [[Bash_Parameters_and_Variables#Parameters_and_Variables|Bash variables and parameters]]



Revision as of 03:55, 26 August 2023

Internal

Identifier (Name)

An identifier is a name given to program element, for example to a variable. In this case, the identifier and the variable are equivalent. Identifiers are also used for functions, classes, labels, and many more elements. Identifiers must differ in spelling and case from the language keywords, or reserved words.

Keyword (Reserved Word)

Reserved words across languages:

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:

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. For Java generics, the ordinary parameters and variables are replaced with type parameters (type variables), and the arguments are replaced with type arguments.

Function parameters in various languages:

Argument

When a function is invoked, we pass an argument for each parameter declared in the function definition. An argument is a value that is passed into the function as function's input. When the function is called with arguments, the values of those argument are copied to the function-scoped variables corresponding to the associated parameters. The argument can be another variable, defined in the block that invokes the function. Usually, and depending on the syntax of the particular language, arguments are passed in parentheses and they are separated by commas.

Function arguments in various languages: