Oppimateriaalin copyright © 2007 Arto Wikla.
Tämän oppimateriaalin käyttö on sallittu vain yksityishenkilöille
opiskelutarkoituksissa. Materiaalin käyttö muihin tarkoituksiin,
kuten kaupallisilla tai muilla kursseilla, on kielletty.
581362 Ohjelmointikielten periaatteet keväällä 2007: 4.
harjoitukset 13.2.
-
[Modified from Scott's Review Questions for Chapter 8, Vihavainen]
Answer the following questions concerning programming languages:
-
What are the purposes of the stack pointer (sp) and
the frame pointer (fp)?
Why does a subroutine often need both?
Why do compilers typically allocate space for arguments in the
stack, even when they pass them in registers?
-
Describe four common parameter-passing modes.
How does a programmer choose which one to use when?
-
How does an inline subroutine differ from a macro?
How does a generic subroutine differ from a macro?
-
Give examples in which it is useful to return a reference
from a function (e.g., in C++).
-
Why do you suppose that variable-length argument lists are so
seldom supported by high-level programming languages?
-
Describe the algorithm used to identify an appropriate handler
when an exception is raised in a language (e.g., in Ada, C++ or
Java).
Explain why it is useful to define exceptions as classes in C++ and
Java.
-
Explain the difference between a coroutine and a
subroutine.
Explain the difference between a coroutine and a
thread.
What was the first high-level programming language to provide
coroutines?
- [Scott 8.1]
Describe as many ways as you can in which functions in Algol-family
programming languages differ from functions in mathematics.
-
- [Scott 8.2] Using your favorite language and compiler, write a program that
determines the
order in which subroutine parameters are evaluated.
- [Scott 8.11]
Can you write a swap routine in Java, or in any other language with
only call-by-sharing parameters? What exactly should swap do in such a
language?
- [Modified from Scott 8.6, Vihavainen, Wikla]
Write (in a language of your choice or an appropriate pseudo-language)
samples of procedures or functions that will have different
effects, depending on whether arguments are passed by
value, by reference, by value/result, or by
name.
Vihje: Nimiparametrivälityksen erilaisuutta voi
havainnollistaa esimerkiksi taulukon alkion ja taulukon indeksin
välittämisellä todellisina parametreina.
- [Scott 8.28] Algol 60 allows labels to be passed as parameters, and allows gotos
to these labels. One can imagine using these "nonlocal gotos" to escape from a nested
function in response to unexpected conditions, but modern language designers
regard label parameters as a bad idea. In what way(s) is the exception handling of
Ada, Modula-3, or C++/Java/C# better?
- [Modified from Scott's Review Questions for Chapter 9, Vihavainen]
Answer the following questions concerning programming languages:
-
What are generally considered to be the three defining
characteristics of
object-oriented programming?
-
Explain why inline subroutines are particularly
important in
object-oriented programming languages.
-
Why is object initialization simpler in a language with a reference
model of variables (as opposed to a value model)?
-
Explain the connection between dynamic method binding and
(inclusion) polymorphism in object-oriented languages.
Explain the difference between static and dynamic method binding
(i.e., between virtual and nonvirtual
methods
and the ways to call them).
Is a virtual method always bind at run time? Explain.
Why does C++ use static method binding by default?
Why do Smalltalk, Eiffel, and Java make all methods
virtual, by default?
- [Täydennetty Scott 9.1, Wikla] Some language designers argue that object
orientation eliminates the need for nested subroutines. Do you agree? Why or why not?
Sisäluokat toivat Javaan Algol-kieliperheen sisäkkäisten aliohjelmien kaltaisen
näkyvyysrakenteen. Kannattiko? Hyötyjä? Haittoja?
Takaisin harjoitusten pääsivulle.