Chapter 5.4- 5.4.3

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

What can things can be declared dynamic?

- Class Members - Properties - method parameters - method return values - local variables

What are the possible binding times?

1) Language Design time 2) Language Implementation Time 3) Compile Time 4) Load time 5) Link time 6) Run time

What are the two disadvantages to dynamic type binding?

1) Programs are less reliable - Dynamic type binding allows any variable to be assigned a value of any type, and incorrect type assignments are not detected as errors (if on the right side) For instance in JavaScript, if i=y; and i was originally a scalar but y is an array, i will produce errors later when used as a scalar as intended 2) cost - costly during execution time.

What is "type inference" ?

1) it is an implicit type declartion 2) The "context" is the type of the value assigned to the variable in a declaration statement.

How much longer does pure interpretation take vs equivalent machine code?

10x

What is a binding?

A binding is an association between an attribute and an entity, such as between a variable and its type or value. Or, between an operation and a symbol.

When is a binding STATIC?

A binding is static if it first occurs before run time begins, and remains unchanged throughout program execution.

What is an explicit declaration?

An explicit declaration is a statement in a program that lists variable names and specifies that they are a particular type.

What is an implicit declaration?

An implicit declaration is a means of associating variables with types through default conventions, rather than declaration statements.

In Java, when are variables bound to a particular data type?

Compile time.

A variable can be declared to use dynamic type binding by including the ________ reserved word in its declaration (for C# 2010)

DYNAMIC reserved word e.g., dynamic any;

When a variables type is ______ bound, its name can be thought of being ________ bound to a type.

Dynamically bound, temporarily bound to a type.

It is important to realize that the type of a variable whos type is ________ bound, may be _________.

Dynamically, temporary.

When is a binding DYNAMIC?

If the binding first occurs during run time--or can change in the course of the program execution.

Examples of Implicit vs Explicit

Implicit can be taken as implied, but explicit means that you state it must be done yourself. Like with casts. Here is an implicit cast: int implicit; implicit = 7.5; The value '7.5' will implicitly be cast as an int. This means the compiler does it for you. Here is explicit: int explicit; explicit = (int)7.5; Here you tell the compiler that you want it cast. You explicitly declare the conversion.

What type of declaration uses "context"

Implicit declaration can be accomplished through context.

What is a "namespace" referring to?

In computer programming, namespaces are typically employed for the purpose of grouping symbols and identifiers around a particular functionality and to avoid name collisions between multiple identifiers that share the same name.

In Perl, what does $ do?

In front of a variable name, it makes the type a scalar. This scalar can hold either a string or a numeric value.

When is a data type, such as int in C, bound?

It is bound to a range of possible values at language implementation time.

When is the asterisk * symbol usually bound?

It is usually bound to the multiplication operation at LANGUAGE DESIGN TIME.

What is the primary advantage of the dynamic binding of variables to types?

It provides more PROGRAMMING FLEXIBILITY

...In this case, the first appears of a variable name in a program constitutes...?

Its implicit declaration.

When is a call to a library subprogram bound to the subprogram code?

Link Time

In what type of languages are all variables references, and don't have types?

Pure objected-oriented languages, like RUBY, all variables are typeless references.

In what languages is type binding dynamic?

Python, Ruby, JavaScript, PHP. JavaScript e.x. : list = [19.2, 3.5]; Regardless of the previous type of the 'list' variable, this assignment causes it to become the name of a single-dimensional array of length 2.

Variables in ______ can reference ANY object..?

Ruby

When are variables declared in Java methods bound?

Run time, (in some cases?)

When the type of a variable is ________ bound, the name of the variable can be thought of as being bound to a type.

Statically bound --in the sense that the type and name of a variable are simultaneously bound.

Consider the C++ statement count = count + 5; When are its parts bound?

The TYPE of count is bound at compile time. The set of possible balues of count is bound at compiler design time. The meaning of the operator (+) symbol is bound at compile time--when the types of its operands have been confirmed** The internal representation of the literal 5 is bound at compiler design time. The VALUE of count is bound at execution time with this statement.

What is "binding time?"

The time at which a binding takes place.

When is a the type of a variable bound in "dynamic type binding?"

The variable is bound to a type when it is assigned a value in an assignment statement. When the assignment statement is executed, the varriable being assigned is bound to the type of the value of the expression on the right side of the assignment.

Why are implicit declarations considered detrimental to reliability?

They prevent the compilation process from detecting some typographical and programmer errors. This can be avoided by requiring names to begin with a special character denoting a specific type to be used. i.e. $ in perl is a scalar.

T/F - due to the nature of hardware/memory, variables are in a sense bound and unbound repeatedly.

True

T/F: You can't write a C program to process data without knowing the type of that data?

True, it lacks the proper dynamic binding abilities needed.

Why is it "costly" to do dynamic type binding?

Type checking must be done at RUN TIME. - Every variable must have a run-time descriptor

What languages use TYPE INFERENCING?

Visual Basic, and the functional languages ML, Haskell, OCaml, and F#.

In Java, a language with static type binding, the compiler__________ detect the error in the assignment of i=y;

WOULD, (i = scalar , y=array) in this case

When might a variable be bound to a storage cell?

When the program is loaded into memory. * That same binding does not happen until run time in some cases, as with variables declared in Java Methods.

A variables type can be changed..

any number of times during program execution. (Mentioned under dynamic type binding)

Any variable can be assigned...

any type value.

"In reality, the NAMES of variables are never..

bound to types"

With dynamic type binding, the type of a variable ..

can not be determined by the spelling of its name.

There has been a significant shift to languages that use _______ type binding

dynamic.

With dynamic type binding, the type of a variable...

is not specified by a declaration statement.

Before a variable can be referenced in a program, ...

it must be bound to a data type.

Implicit variable type binding can be done by

naming conventions. In this case, the compiler/interpreter binds a variable to a type based on the syntactic form of the variable's name

Languages with static type bindings are seldom implemented by..

pure interpretation.

Languages that have dynamic type binding for variables are usually implemented using...

pure interpreters rather than compilers.

In Java, the variable references are restricted to...

referencing one specific type of value.

In some languages that use _________ binding, such as C and C++, the above error can also happen . When it happens, the RHS of the assignment is automatically converted to the LHS type.

static

Both Explicit and implicit declarations create...

static bindings to types.

Implicit variable type binding is done by..

the language design processor--either a compiler or interpreter.

How can types be specified statically?

through some form of explicit or implicit declaration.

Examples of Type Inference by context.

var sum = 0; (int) var total = 0.0; (float) var name = "Fred"; (string) These are STATICALLY typed variables--their types are fixed for the lifetime of the unit in which they are declared.

Names can be bound to variables and

variables can be bound to types..

To determine the value of a variable, it may be necessary to know..

when the variable was bound to storage, and with which statement or statements.

Are languages dramatically different if their types are statically or dynamically bound?

yesh.


Kaugnay na mga set ng pag-aaral

Chemistry Test #2 Chapter 7 and 8

View Set

BLAW 17: Contracts -- Third Parties' Contract Rights & BLAW 18: Performance and Remedies

View Set

EDP 350E Brown - Exam 1 (Spring 2022)

View Set

Chapter 20 Pathophysiology NCLEX-Style Review Questions

View Set

PARAGRAPHS: Paragraph Flow, paragraph editing Quiz

View Set