Saturday, April 02, 2005

Types

"Real Programmers don't write in PASCAL, or BLISS, or ADA, or any of those pinko computer science languages. Strong typing is for people with weak memories."
(Vleck 1982)

Introduction

Types are important because they limit what a programmer can do with values and operators. If operators and values used in expressions are incompatible, then the compiler may automatically warn the programmer about the mistake. Such warnings could help the programmer to avoid some serious errors.

Clearly, values such as 42, 'a' and true are somehow different from one another.

Also, an operator should not be compatible with all types of values. The following program is illegal:

public class Main {
    public static void main(String[] args) {
        System.out.println(42 / true); // error
    }
}

because the / operator does not make sense with these values.

Concept: A type defines a set of values and a set of operators.

Concept: Every value is of a type.

Concept: Every expression has a type.

No comments: