Review Guide/ Qs & Ans/ 2024-2025.
Strong typing and weak typing. Static typing and dynamic typing. (Examples.
Why). - Answer: Strong Typing - a language is said to be strongly typed if it
prohibits, in a way that the language implementation can enforce, the application
of any operation to any object that is not intended to support that operation to
any object that is not intended to support that operation. (e.g., Java, C++,) Ruby is
strongly typed because once it knows the type of an object, it expects you to do
something that makes sense with it.
Ex:
x = "3"
y = x + "ho!"
#=> "3ho!"
but
,x = "3"
y=x+3
will produce an error.
------------------------------------------Weak Typing - a language that is being lenient
about what you can do with your typed variables. Javascript, however, is
dynamically but weakly typed because it lets you mix types together in your
expressions without throwing an exception. The danger? If you're not careful you
will get weird results.
----------------------------------------
Statically Typing - a language is said to be statically typed if it is strongly typed and
type checking can be performed at compile time.language has a type system that
is checked at compile time by the implementation (a compiler or interpreter) and
it is strongly typed. (e.g. Ada, Pascal, Lisp)
------------------------------------------
Dynamic Typing - Dynamic type checking is a form of late binding, and tends to be
found in languages that delay other issues until run time as well. (e.g., Python,
Ruby, Lisp)
Some languages have both static and dynamic type checking.
- Pascal, Java etc are mostly static typing.
- Python, PHP, and most script languages are dynamic typing.
- C++ are combined (support dynamic casting)
, Reference variables and value variables. - Answer: Reference Variable - It provides
an alias (alternative name) for a previously defined variable. References cannot be
null because every reference refers to some object.
Ex: int foo;
int& bar = foo;
bar is now a reference which means that bar holds the location of memory where
foo lies.
Value Variable -
d = a;
a = b + c;
In the first statement, the right hand side of the statement refers to the value of a,
which we wish to place into d. In the second statement, the left hand side refers
to the location of a, where we want to put the sum of b and c.
•Variables as values vs. variables as references
-value-oriented languages
•C, Pascal, Ada
-reference-oriented languages
•most functional languages (Lisp, Scheme, ML) •Clu, Smalltalk
-Algol-68 kinda halfway in-between -Java deliberately in-between
•built-in types are values •user-defined types are objects - references