CS374: Programming Language Principles - Programming Paradigms
Activity Goals
The goals of this activity are:
- To define the imperative, declarative (functional and logic), object-oriented, and scripting programming paradigms
- 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
- What defines a statement?
- What, in general, does a statement realy do?
- At what points do the value of root change?
- What would happen if
a
is 0?
- 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
- What is the value of
bill->salary
after the call to tax()
?
- The above program has a memory leak. Which variable should also be freed?
- Why is there a
+1
in the malloc
call on bill->name
?
- 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
- How did each file change above by converting the
Vehicle
interface to a class?
- By converting the
Vehicle
interface to a class, what can we now define in a Vehicle
that we could not define in the interface
?
- You can implement an
interface
; what is the keyword to subclass a class?
- From context, what do you think the abstract keyword means in the
Vehicle
class?
- From context, what do you think the call to
super()
does?
- 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?
- 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
- At what points do the value of
root
change? Where are they changed, and where are they effective?
- What would happen if
a
is 0?
- How many copies of
discriminant
exist on the call to calcroot
?
- How does the
calcroot
function know to use the discriminant
variable in its local function?
- What would happen if
discriminant
was modified inside calcroot
? Why is this different than for the root
variable?
Model 5: Declarative Languages - Functional
Questions
- What is a statement in Scheme?
- What shared variables exist in this program?
- What are some potential advantages of Functional Programming as a paradigm?
Model 6: The Scheme Programming Language
Questions
- How are function parameters handled in Scheme? Are they passed by value or by reference?
- What is a function in Scheme? How is it represented?
- What does
czr
do in your own words?
- 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.
- Diagram the binding of the values in the call to
plusminus
to the anonymous lambda function.
- 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
- What query would result in a
yes
response according to the prerequisite rules above?
- In your own words, what does the
take_before
clause specify, and how does it do so?
- 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
- Describe, in your own words, what this program does.
Model 9: Applications of the Declarative Paradigm - Pythonic List Comprehension
Questions
- What are the advantages and disadvantages of each approach?
- Which version do you find more convenient and why?
Model 10: Scripting Languages - Bash
Questions
- What is a statement in this language?
- How are variables expanded?
- What potential benefit can you see with the use of shell scripting?
- Are scripting languages imperative or declarative?
Model 11: Programming Constructs in bash
Questions
- What do you think
$1
means?
- If
$1
is 5, what is the final value of x
?
- Why was the
\
character necessary in the x=$(expr $1 \* 2)
command?
- What do each of the variable expansions do in the first example above?
- 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
- 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.