CS374: Programming Language Principles - Programming Paradigms

Activity Goals

The goals of this activity are:
  1. To define the imperative, declarative (functional and logic), object-oriented, and scripting programming paradigms
  2. To explore concurrency within programming paradigms

Supplemental Reading

Feel free to visit these resources for supplemental background reading material.

The Activity

Directions

Consider the activity models and answer the questions provided. First reflect on these questions on your own briefly, before discussing and comparing your thoughts with your group. Appoint one member of your group to discuss your findings with the class, and the rest of the group should help that member prepare their response. Answer each question individually from the activity on the Class Activity Questions discussion board. After class, think about the questions in the reflective prompt and respond to those individually in your notebook. Report out on areas of disagreement or items for which you and your group identified alternative approaches. Write down and report out questions you encountered along the way for group discussion.

Model 1: Imperative Languages

Questions

  1. What defines a statement?
  2. What, in general, does a statement realy do?
  3. At what points do the value of root change?
  4. What would happen if a is 0?
  5. How can we represent this program using an Object-Oriented style? What state might the object represent?

Model 2: The C Programming Language and Memory Management

Questions

  1. What is the value of bill->salary after the call to tax()?
  2. The above program has a memory leak. Which variable should also be freed?
  3. Why is there a +1 in the malloc call on bill->name?
  4. Suppose we had set p equal to a newly malloc'ed person in tax. How would this affect bill?

Model 3: The Object-Oriented Paradigm

Questions

  1. How did each file change above by converting the Vehicle interface to a class?
  2. By converting the Vehicle interface to a class, what can we now define in a Vehicle that we could not define in the interface?
  3. You can implement an interface; what is the keyword to subclass a class?
  4. From context, what do you think the abstract keyword means in the Vehicle class?
  5. From context, what do you think the call to super() does?
  6. Notice that some elements are scoped to be public and private, like before, but now some items are protected. Which items are protected, and in which files do they reside? What do you think this scope allows/disallows?
  7. Sketch out an object-oriented design representing students and courses, in which students are enrolled in one or more sections of the course.

Model 4: Imperative Languages

Questions

  1. At what points do the value of root change? Where are they changed, and where are they effective?
  2. What would happen if a is 0?
  3. How many copies of discriminant exist on the call to calcroot?
  4. How does the calcroot function know to use the discriminant variable in its local function?
  5. What would happen if discriminant was modified inside calcroot? Why is this different than for the root variable?

Model 5: Declarative Languages - Functional


Questions

  1. What is a statement in Scheme?
  2. What shared variables exist in this program?
  3. What are some potential advantages of Functional Programming as a paradigm?

Model 6: The Scheme Programming Language





Questions

  1. How are function parameters handled in Scheme? Are they passed by value or by reference?
  2. What is a function in Scheme? How is it represented?
  3. What does czr do in your own words?
  4. Write a function to count the number of items in a list using a recursive call and a base case, using czr as a guide to traversing a list.
  5. Diagram the binding of the values in the call to plusminus to the anonymous lambda function.
  6. What is the result of the map/apply sequence? What would happen if map were applied to only a single list?

Model 7: Declarative Languages - Logic

Questions

  1. What query would result in a yes response according to the prerequisite rules above?
  2. In your own words, what does the take_before clause specify, and how does it do so?
  3. Write a Horn Clause that specifies that one might go outside if it is warm and not raining outside.

Model 8: Declarative Languages - Prolog

Questions

  1. Describe, in your own words, what this program does.

Model 9: Applications of the Declarative Paradigm - Pythonic List Comprehension

Questions

  1. What are the advantages and disadvantages of each approach?
  2. Which version do you find more convenient and why?

Model 10: Scripting Languages - Bash

Questions

  1. What is a statement in this language?
  2. How are variables expanded?
  3. What potential benefit can you see with the use of shell scripting?
  4. Are scripting languages imperative or declarative?

Model 11: Programming Constructs in bash


Questions

  1. What do you think $1 means?
  2. If $1 is 5, what is the final value of x?
  3. Why was the \ character necessary in the x=$(expr $1 \* 2) command?
  4. What do each of the variable expansions do in the first example above?
  5. What would happen if the -lt in the loop above was modified to <? Similarly, what is the difference between -eq and = in bash?

Model 12: Concurrent and Socket Programming in the Go Language

Concurrency in the Go Language


Non-Blocking Concurrency Channels in the Go Language


Questions

  1. How might you add concurrency to a socket program to allow the program to send data without having to wait to receive a message?

Submission

Submit your answers to the questions using the Class Activity Questions discussion board. You may also respond to questions or comments made by others, or ask follow-up questions there. Answer any reflective prompt questions in the Reflective Journal section of your OneNote Classroom personal section.