Variable

From Jonathan Gardner's Tech Wiki
(Redirected from Variables)
Jump to: navigation, search

Introduction

In most programming languages, variables are defined to temporarily hold values.

What you can do with a variable

  • Define a new variable.
  • Change the value of the variable. (Some languages like Haskell do not allow this.)
  • Access the current value.

Definition

When you define a new variable, you generally have to assign to it the following attributes:

  • A scope
  • A name
  • A type
  • An initial value

Name

The name you use is important. Every language has limits on what names are available, and programming conventions further limit your options. Choose your variable names well, and you have self-documenting code. Choose poorly and no amount of documentation will make the code clear.

See /Name

Type

Typing is how the programming language keeps track of which variables hold what type of data.

See /Type.

Scope

Scope determines where the variable exists, meaning, what code can access it and how.

See /Scope

Value

The value is the thing the variable is holding. See /Value