Pre-assessment notes

Statically typed

Quite a few people indicated that they didn't know this, and quite a few of those who did have a go got it wrong.

A language is "statically typed" if the types of things (variables, expressions, whatever) are known at compile time, not only at run time. The implication is that if they don't make sense, the programmer can be informed then.

Haskell and Java are both statically typed languages; Haskell is a functional language, Java is an object oriented language. By contrast, Smalltalk is a dynamically typed object oriented language. Lisp is a dynamically typed functional language. PHP, Python and Perl are dynamically typed imperative languages. Note that in particular, any language that does not have a compiler - it is interpreted instead - is dynamically typed!

Many people confused the idea of the compiler knowing the types with the programmer having to specify them. There's certainly a correlation, but type inference is what breaks that connection: in many languages, an early stage of compilation is for the compiler to infer what types things must have. (If you think about it, there is always an element of this. We know that if i and j are both integers then so is i + j, and we expect the compiler to infer it: we don't expect to have to declare the type of that expression! What differs between languages is how much type inference there is. In the statically typed language ML, for example, the programmer basically never needs to declare types, though they may for readability.) Once types are known - whether by inference or by the programmer specifying them - type checking is the process that checks whether the types fit together correctly.

Many people perhaps guessed that "static" should mean "unchanging". In fact, even in dynamically typed languages, where types are not identified and checked until run time, it's rather rare for the type of a variable to change. The only language I know well where a single variable can be treated as having different unrelated types, depending on context, is Perl; even there, the variable doesn't actually change types (so as to be able to store different values, say). Someone mentioned var in Javascript as an example of this? I don't speak Javascript though. OO polymorphism can be seen as a special case of this, though, where the types have to be related in a certain way: see later.

Some people were confused with the notion of static method, attribute, inner class etc. in Java - confusingly, indeed, this is not a closely related idea; best to think of it as happening to use the same word. Once person was confused with the idea of a static variable in C - again, this is a confusing terminology overload.

A few examples of correct answers:

A few examples of incorrect answers (many of them partially correct, but see above):
This page is maintained by Perdita Stevens (perdita@inf.ed.ac.uk)


Home : Teaching : Courses : Seoc : 2015_2016 : Preassessment 

Informatics Forum, 10 Crichton Street, Edinburgh, EH8 9AB, Scotland, UK
Tel: +44 131 651 5661, Fax: +44 131 651 1426, E-mail: school-office@inf.ed.ac.uk
Please contact our webadmin with any comments or corrections. Logging and Cookies
Unless explicitly stated otherwise, all material is copyright © The University of Edinburgh