Similarly, a computer program stores data in
variables, which represent storage locations in the
computer's memory. The contents of these memory locations, at any given point in the program's execution, are called the program's
state. A more specialized definition of state is used for computer programs that operate serially or sequentially on
streams of data, such as
parsers,
firewalls,
communication protocols and
encryption. Serial programs operate on the incoming data characters or packets sequentially, one at a time. In some of these programs, information about previous data characters or packets received is stored in variables and used to affect the processing of the current character or packet. This is called a
stateful protocol and the data carried over from the previous processing cycle is called the
state. In others, the program has no information about the previous data stream and starts fresh with each data input; this is called a
stateless protocol.
Imperative programming is a
programming paradigm (way of designing a
programming language) that describes computation in terms of the program state, and of the statements which change the program state. Changes of state are implicit, managed by the program runtime, so that a subroutine has
visibility of the changes of state made by other parts of the program, known as
side effects.
Object-oriented programming attempts to improve on the
imperative and
procedural programming paradigms by
encapsulating related state (and behavior) within
objects. The state of an object is often
hidden in an attempt to isolate it from other objects and reduce
coupling. State that is hidden in this way is often referred to as the "internal state" of the object. In
declarative programming languages, the program describes the desired results and doesn't specify changes to the state directly. In
functional programming, state is usually represented with
temporal logic as explicit variables that represent the program state at each step of a program execution: a state variable is passed as an
input parameter of a state-transforming function, which returns the updated state as part of its return value. A
pure functional subroutine only has visibility of changes of state represented by the state variables in its scope. ==Finite-state machines==