Pre-assessment notes
Statically typed
I'd say these answers are correct. Note, though, that we're actually
interested in all types, not just the types of variables - e.g. expressions
have types, too. The implication of types being known at compile time 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
languate, Java is an object oriented language. By contrast, Smalltalk is a
dynamically typed object oriented language. Lisp is a dynamically typed
functional language.
- Being "statically typed" means to have the program recognize what type that "thing" is during "compile time" rather than at "run time."
- The type of a variable is known at "compile time" rather than "run time".
- statically typed means that the variable type is known at compile time
- If the type of a variable is known at compile time.
And this is true, though not complete:
- It's an attribute of a programming language - means that types are statically checked - not sure what exactly that means though.
Types being known at compile time is a different thing from the
programmer needing to give types in the code. Types may be inferred,
instead, and this can happen at compile time or at run time. If you
think about it, we always have some type inference: if you have
specified that i and j are integers, you routinely assume that you do
not have to specify that i + j is an integer, because you expect the
computer to work out - that is, infer - that information. Some
languages do a lot of type inference, others much less. Standard ML is
an example of a statically typed language with lots of type inference:
typically, Haskell programmers write down more types than ML
programmers do, but they can often get away with not doing so; Java
has relatively little type inference. So these are not right:
- All data must be declared as a type (string, int, char.etc)
- Statically Typed means that all variables are predefined in the data type value(s) they may hold.
- The compiler is given the data type of the variable.
- Types of variables are explicitly defined in the code.
- Statically typed means that the programmer doesn't need to specify what type each variable is.
- note that the last one of these says the opposite of the others -
and this one nicely hedges its bets with "normally" :-)
- I understand what is "dynamically typed", so I assume "statically" is
the antiform of this. Thus "statically typed" means that variables
are given types on compile type (and this is normally done by the
programmer explicitly writing down the type of a particular variable
e.g. String rather than just "var" in Python's case)
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). 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.
- This means a variable's type is defined when the variable is and it
can only be assigned values of that type.
- A type which does not change no matter what
- Every variable has a specific, unchaning type specified by the programmer.
- a programming language in which the type of a variable is defined
permanently at the instant that variable is instantiated.
- I guess it means a data type not easily changed or not flexible
- Variables must always be declared to have a certain type (e.g.
integer, character, boolean) that cannot be left ambiguous or changed
later.
- It means that the type of a variable is declared at the start and it
remains fixed all through its scope
(Those two also had elements of "no type inference".)
- That the data types are fixed at compile time and can't be changed
later on. For instance, in Java it's impossible to declare a string and
later treat it as a number, whereas in Python or PHP that would not cause
any issues (other than the result being meaningless).
(wouldn't you get a run time type error? I thought I knew that in python
you would; I haven't programmed in php... maybe that's included in
meaningless result)
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.
- Using static variables.
- means there is only one copy of it in the program, and is in global scope.
- Unique and the object lifetime is as long as the program.
- It is per class
- There is only one instance of whatever is being statically typed which can not be changed from actions the code takes .
- Means it's not bound to an object
A few answers were idiosyncratically wrong:
- the value may not be altered by other parts of the program
(thinking of another way Java uses "static" perhaps)
- Makes the variable only accessible from within the class.
(confusing with private)
- It means that the type of variables is known at running time.
(almost the opposite of the truth: by run time, the type of variables
really has to be known, the question is whether they are known before
then!)
- Statically typed is where a program is written in its entirety,
compiled, and then run all at once, as opposed to dynamically typed, where
the code is entered line by line and is interpreted as it is entered
(getting at the distinction between compiled and interpreted; this is
relevant as an interpreted language cannot be statically typed! But a
language can be compiled, and yet dynamically typed.)
- Statically typed means that the code is not executed a the point it is
typed.
Several people, naturally, gave answers that were mixtures of right and wrong: hopefully it's clear enough by now which bits are which:
- Statically typed means once a variable (functions etc..) is
declared as a type, the data type of the variable (functions etc..)
cannot be changed. Before compile, compilier checks all source code to
ensure that all data coherent with declearation type, avoiding
compiling error to occur.
- Statically typed languages have explicit types written into the
code, i.e. a specific datatype put in a variable declaration. They are
different from dynamically typed languages where types are decided at
compile or run-time based on variable assignments.
This page is maintained by
Perdita Stevens (
perdita@inf.ed.ac.uk
)