Oppimateriaalin copyright © 2009 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ä 2009: 4. harjoitukset

  1. [Modified from Scott's Review Questions for Chapter 8, Vihavainen] Answer the following questions concerning programming languages:

    1. Describe four common parameter-passing modes. How does a programmer choose which one to use when?
    2. How does an inline subroutine differ from a macro? How does a generic subroutine differ from a macro?
    3. 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?
    4. [*]Explain and give examples of exception handling in Scala. What are the differences compared to Java? Can you see why these differences were made?

  2. [Scott 8.1] Describe as many ways as you can in which functions in Algol-family programming languages differ from functions in mathematics.

  3. [Strongly modified Scott 8.6] Consider the following subroutine and call:
       procedure f(x, y, z)
          x := x + 1
          y := z
          z := z + 1
       . . .
       i := 1; a[1] := 10; a[2] := 11
       f(i, a[i], i)
       println(i, a[1], a[2])
    
    What does the program print, when parameters are passed (a) by value, (b) by reference, (c) by value/result, or (d) by name? Explain why!

  4. [Scott 8.10 and 8.11]
    1. Suppose you are writing a program in which all parameters must be passed by name. Can you write a subroutine that will swap the values of its actual parameters? Explain. (Hint: consider mutually dependent parameters like i and A[i].)
    2. 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?

  5. [Modified from Scott's Review Questions for Chapter 9, Vihavainen] Answer the following questions concerning programming languages:

    1. [*]What are generally considered to be the three defining characteristics of object-oriented programming?
    2. Why is object initialization simpler in a language with a reference model of variables (as opposed to a value model)?
    3. 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).

  6. [Modified Scott 9.1] Some language designers argue that object orientation eliminates the need for nested subroutines. Do you agree? Why or why not? The inner classes brought "nested classes" to Java. Can you see, why they ever wanted to have these in Java? Was it a good or bad idea?

  7. Explain the terms trait and mix-in in Scala language. Give program examples of situations, where this technique is natural and leads to clear program structure. What are the differences between traits and multiple inheritance? What are the differences between traits and Java-style interfaces?


Takaisin harjoitusten pääsivulle.