Unlocking Programming: Expressions and Values
© 11 Jul 2011 Luther Tychonievich
Licensed under Creative Commons: CC BY-NC-ND 3.0
other posts

Unlocking Programming

Part of a series of posts explaining programming for the lay-person.


This is part of a series of posts; see the introduction to this series.

In programming an expression is not an expression at all but rather the description of a thing or value. “‍Myself‍”, “‍a list of all the people who’ve ever been to Kensington‍”, and “‍the third door from the right‍” are all expressions. “‍Three‍” is an expression if you are dealing in mathematics where numbers are nouns instead of adjectives. “‍It is raining‍” can also be seen as an expression, though to explain why we must discuss values.

The value of an expression is the thing it identifies. More accurately, a value is the representation of a thing that is used to compute additional values, a somewhat circular definition and not important for this discussion. The value of “‍myself‍” is a person, the value of “‍a list of all the people who’ve ever been to Kensington‍” is a large book filled with expressions describing people, and the value of “‍the third door from the right‍” is a physical door.

The value of “‍it is raining‍” is either “‍true‍” or “‍false‍”. At the time and place where this is being written, its value is “‍false‍”, though at the time and place of reading it might be “‍true‍” instead. This variability comes because the expression “‍it is raining‍” depends on a context (“‍it‍”).

An important process in computing is evaluation, or the replacing an expression with its described value. If I evaluate “‍an apple if it is raining, otherwise a teacup‍” at the time and place where I am writing this text, I end up with a teacup, because where I am right now that expression describes a teacup. If you evaluate it you might end up with an apple instead, as might I if I evaluate it later this afternoon.

This distinction between expressions and their values is an important one in computation, though not one often mentioned. Most computing languages are defined to always evaluate expressions as soon as they first appear and utilize their values thereafter, though there are situations where this is a bad idea and where expressions are evaluated only when absolutely necessary.

That’s it. Expressions, Values, and Evaluation.

Looking for comments…

Loading user comment form…