The terms are somewhat language-specific; they were first introduced in CPL. Being an lvalue or an rvalue is a property of an expression; that is, every expression is either an lvalue or an rvalue.
You will often find explanations that deal with the left and right side of an assignment. That is the historical origin of the letters l and r in lvalue and rvalue, but it does not hold anymore. For example, there are lvalues that can not stand on the left side of an assignment (expressions denoting arrays and constant variables come to mind, but also class types where the assignment operator has been hidden or deleted), and at least in C++, there are rvalues that can stand on the left side of an assignment.
The best definition that I know of is: an lvalue is an expression to which the unary &
operator can be applied, whereas an rvalue is an expression to which the unary &
operator can not be applied. (This is not entirely true in C++ if you overload said operator, but that's probably very bad practice.)
Since C++11, the language also has the notions of xvalues, prvales und glvalues (see here and here).
Is pointer constant is a rvalue?
Expressions that denote pointer variables like p
are lvalues. Expressions that denote pointer values like &i
are rvalues. Both of them can be either const
or non-const
; that's completely orthogonal.
Java doesn't have the notion of lvalues, but in §15.1 the Language Specification states:
When an expression in a program is evaluated (executed), the result denotes one
of three things:
- A variable (§4.12) (in C, this [expression] would be called an lvalue)
- A value (§4.2, §4.3)
- Nothing (the expression is said to be void)
Let's say for instance we have an app, it works perfectly, aside from it crashing every 5 minutes, but it's back up instantly without data loss.
That in my mind is reliable, but not stable.
I can rely on it not losing data and working correctly, despite it not being stable.
In fact, the internet is basically that. It's far from stable—connections drop and reappear, packets collide and are lost, and all kinds of other unstable things happen. However, it's pretty amazing how reliable it is given all the instability inherent in it.
Best Answer
subprogram, subroutine
"subroutine" probably comes from assembly language. Some processors include instructions to support subroutines as a way of organizing code and reusing common sections of code. For example, the 6502 processor had JSR (jump to subroutine) and RTS (return from subroutine) instructions. I remember it also being used a lot in structured programming, in which a program is a hierarchy of units of code which were sometimes called subroutines or subprograms. IMO, these are the most generic terms for some unit of code to which control is temporarily transferred for the purpose of completing a given task.
function, procedure
These are often used interchangeably, but in some languages there's a distinction. In Pascal, a function is a subprogram that returns a value, while a procedure is a subprogram that doesn't. In C and related languages, every subprogram has a return type (even if it's
void
), so there's no distinction.method, member function
These are two names for the same thing -- essentially a function that's associated with a given class or object.
operator
Every language has a set of built-in operators. In some languages, such as C++, operators are functions that can be overridden (i.e. replaced) and/or overloaded (i.e. defined for new types).
anonymous function
This refers to a function without a name. Anonymous functions are essentially blocks of code that can be assigned to variables or passed as parameters for subsequent use, for example as a completion routine.
closure, lambda expression, block
A closure is a chunk of code that's bound to a set of variables. I think of closures as anonymous functions plus context.