CPSC 210 Lecture Notes - Lecture 4: Turing Award, Joshua Bloch, Postcondition
Document Summary
Many object-oriented programming languages use type hierarchies and polymorphism to simplify the expression of software. Each piece of data a software program creates or uses has a type that de nes the operations that can be performed on that piece of data. Some programming languages infer the type of a piece of data. For instance, in scheme, you could write a function to calculate the cost of a bus trip if you need to buy n tickets as: (define (cost-of-bus-trip n) (* 2. 50 n)) This function attempts to treat the value passed as a parameter (i. e. n) as a number because it is used in an operation (*) that operates on numbers. If a string is passed, as in (cost-of-bus-trip ), the interpreter will complain that the expected type of n is a number. In other programming languages, such as java, each variable used in a program must have a type declared by the programmer.