Kamis, 30 Oktober 2014
Assignment Chapter 5
Programming Language Chapter 5
ASSIGNMENT 5
30 Oct 2014
REVIEW QUESTION
11. Q: What are the advantages and disadvantages of dynamic type binding ?
A:
-Advantages = It is more easy to write generic code.
-Disadvantages = High Cost to check type and interpretation
12. Q: Define static, stack-dynamic, explicit heap-dynamic, and implicit heapdynamic variables. What are their advantages and disadvantages ?
A:
- Static -- memory alloc'd before execution. Stays throughout. Adv: runtime efficient, history-sensitive subprograms. Disadv: no recursion.
- Stack dynamic - memory alloc'd from system stack when decl elaborated. Adv: recursion, conserves memory. Disadv: no history sensitive subpgms, less run-time efficient than static.
- Explicit heap-dynamic -- memory alloc'd/freed by pgmer from "heap". Adv: flexible storage mgmt. Disadv: less effiicent than stack-dyn; Error prone in pairing new/delete stmts.
- Implicit heap-dynamic -- heap memory alloc'd/freed by assignments. Adv: highext flexibility. Disadv: run-time cost to maintain all the dynamic attrs; Reduced compiler error detection.
13. Q: Define lifetime, scope, static scope, and dynamic scope.
A:
-Lifetime -- when memory is alloc'd for a variable (when in existence).
-Scope -- portions of pgm variable can be referenced or set.
-Static scope -- scope based on source pgm text (static ancestors).
-Dynamic scope -- scope based on run-time call sequence.
14. Q: How is a reference to a nonlocal variable in a static-scoped program connected
to its definition ?
A:
A reference to a non-locally variable in a static-scoped language with nested subprograms requires a two step access process:
1. Find the correct activation record instance
2. Determine the correct offset within that activation record instance
15. Q: What is the general problem with static scoping ?
A:
Usually too much access. Scope structure destroyed as pgm evolves.
Problem Set
1. Q: Which of the following identifier forms is most readable? Support your decision.
SumOfSales
sum_of_sales
SUMOFSALES
A: Sum_of_sales is the most readable. It is because it’s doesn’t have any problem with case sensitive, because the following identifier does not use any caps lock.
2. Q: Some programming languages are typeless. What are the obvious advantages
and disadvantages of having no types in a language?
A:
a. Advantages:
- The only advantage is that is allows coders to write sloppy programs quickly.
b. Disadvantages:
- You are not in control of the data and variables, the compiler or interpreter is.
- If you mis-assign variables, there is no way for the compiler to catch any of your mistakes. It just “does what you said”, even if it is wrong.
- Supporting programs in a type-less language is much more difficult that in a strongly types one. It is often very difficult to determine what the original programmer wanted to do.
3. Q: Write a simple assignment statement with one arithmetic operator in some
language you know. For each component of the statement, list the various
bindings that are required to determine the semantics when the statement is
executed. For each binding, indicate the binding time used for the language.
A:
(C++)
int count;count = count + 5;
Possible types for count: set at language design time. Type of count: bound at compile time.
Set of possible values of count: bound at compiler design time. Value of count: bound at execution time with this statement. Set of possible meanings for the operator symbol ““:*bound at language definition time.*Meaning of the operator symbol “” in this statement: bound at compile time.
Internal representation of the literal “5”: bound at compiler design time.
4. Q: Dynamic type binding is closely related to implicit heap-dynamic variables.
Explain this relationship.
A: Implicit heap-dynamic variables acquire types only when assigned value, which must be at runtime. Therefore, this variable are always dynamically bound to types.
5. Q: Describe a situation when a history-sensitive variable in a subprogram is
useful.
A: To describe a situation when a history-sensitive variable in a subprogram is useful, suppose that a FORTRAN subroutine is used to implement a data structure as an abstraction. In this situation, it is essential that the structure persists between different calls to the managing subroutine.
Langganan:
Posting Komentar (Atom)
Entri Populer
-
Ada hal yang pengen gua ceritain disini . Hal yang pasti semua orang rasain juga, beda sikap antara orang yang bener-bener suka sama ya...
-
Sebulan yang lalu gua masuk UI, dan ternyata murah sekali masuk UI itu . Hanya seribu rupiah bisa masuk ke salah 1 dari 10 Universitas terb...
-
Programming Language Chapter 5 ASSIGNMENT 5 30 Oct 2014 REVIEW QUESTION 11. Q: What are the advantages and disadvantages of dynamic ty...
-
Diliat dari data dan fakta dilapangan, gua sebenernya ngiri sama supir angkot, semua orang membutuhkan dia, apalagi cewek, yang biasa...
-
hmmm gue mau ngereview tentang buku yang 1 bulan lalu yang gue beli di gramedia. yaitu buku Kelakar Tanpa Batas karya Om Sammy @notaslimboy....
-
JAKARTA - Pemandangan serupa kala demam AFF Suzuki Cup 2010 tampak di Lapangan C Gelora Bung Karno, Senayan, Jakarta, Jumat (7/1/2011) pagi...
-
Oke, ini cerita yg uda lumayan lama. Kejaidannya itu waktu gue masih Kelas 3 SMP. Chekidot! Namanya Siti Rahma Hamidah (gue samar...
-
Ni gan bagi yang suka Owl city ai kasih tau sejarahnya buat yang suka owl city ini sejarah nya cekibrottt Owl City. Musik elec...
-
11. What primitive control statement is used to build more complicated control statements in languages that lack them? -> Pemilihan P...
-
Kemampuan menulis materi stand up comedy adalah hal paling dasar yang harus dimiliki seorang stand up comedian, materi inilah nantinya ya...
Tidak ada komentar:
Posting Komentar