/* What are the types in this program?
— String[]
— function,class are those types?
Copyright By PowCoder代写 加微信 powcoder
What is a type?
— a format of data
— something with values
— constraints/rules on data
— kind of data
— a way for the bytes to be interpreted
— a proof
— a type is a proposition in curry-howard
What is the purpose of types?
— For the compiler
— To make sure our program is correct
— To constrain behaviour
— To eliminate runtime errors
— Give meaning to the data
— To use the best representation for the data for example
for a float and integer would be different
— To know the structure for the data that has been stored
— Make your code readable
— An abstraction instead just 0:s and 1:s
— Allows generation of autotests
Types is a way of constraining which programs we’re allowed to write.
What kind of errors do you think the Java type system is meant to avoid?
— trying to use methods that don’t exists
— Access to unassigned memory, forbidden files
— allow you to ignore a ton of cases in your code that you
don’t want to worry about
— less ambiguous semantics
— If a variable is declared to have a type T,
then any value that the variable holds
at runtime must be an element of T. (subject reduction)
“well-typed programs reduce to well-typed programs”
U: Hey dev, what does language construct Foo mean?
A: (Garbage tier) — Well, in the jbljwdbaljdb phase of the compiler
it will generate a jmp instruction, then… smells like you have no
way of explaining what your programs mean, *outside* of how they
happen to be compiled. you may have failed to provide an abstraction
that allows your programmers not to worry about low-level details.
A: (Mid tier)
— Well, it causes the
is a concept that makes sense on the abstraction level of the program.
A: (S-tier)
— A *mathematically precise* definition of what the language
construct Foo does.
class Shape { }
class Rectangle extends Shape {}
class Circle extends Shape {}
public class Types {
public static void main(String[] args) {
Shape[] rs = new Shape[10];
rs = new Rectangle[10];
Circle c = new Circle();
rs[0] = c;
System.out.println(“Hello world!”);
/* Subject-verb-object phrase
subject (noun phrase) verb object
————————————— ——- —————
Buffalo buffalo Buffalo buffalo buffalo buffalo Buffalo buffalo.
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com