<slidy theme="aa" />
A Computer Glossary
print "Hello world!"
Imperative & Declarative Languages
Imperative, a linguistic reference to the command of language, as in "put the candle back".
Imperative languages are:
- Explicit about how to do something.
- PHP (though it's itself embedded within HTML, a declarative language)
- C, C++
- A "macro" in an application like Photoshop
A silly example, of an "imperative" style program.
To exit a room: 1. Walk to the door. 2. Is the light on? YES?: Turn off the light. NO?: do nothing. 3. Open the door. 4. Walk outside.
Declarative, a linguistic reference to the descriptive mood of a language as in "The sky is blue".
- Broadly speaking describe conditions to be met,
- Must be interpreted, to be converted into actual results
- Is therefore open to responding to different contexts
- Examples of declarative languages would be:
- CSS (Cascading Style Sheets)
- SQL (or Structured Query Lanuage used to describe data to access a database)
- LISP, Prolog, Haskell ("higher level" programming languages)
- Regular Expressions (a pattern language to search & replace text)
A silly example of a declarative style program:
Saving Electricity Policy When a room is unoccupied, the light should be switched off.
Some expressions for the console...
5 * 3
100 - 1
3 * 8
"Tristram" + "Shandy"
5 + 2
"5" + 2
"5" - 2
Assignment is the process of storing an expression in a "name", called a variable.
x = 5 * 3
name = "Tristram"
In-place Assignment (++)
A typical thing to do use a variable's current value to compute some new value (ie incrementing a numeric variable, or adding something to the end of a textual variable). When an expression using a variable is then assigned to the same variable name, it's called an "in-place assignment". There's no confusion about then things happen, the expression (on the right of the equals sign) is computed first using the current value of the variable, and then the new value is stored in the variable, effectively changing it's value (and losing the old value).
x = 7
x = x + 1
x += 1
name = "Tristram"
name = name + " Shandy"
name += " Shandy"