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, and compare with your group to prepare for our whole-class discussion. 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 totax()
? - The above program has a memory leak. Which variable should also be freed?
- Why is there a
+1
in themalloc
call onbill->name
? - Suppose we had set
p
equal to a newlymalloc
'ed person intax
. How would this affectbill
?
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 aVehicle
that we could not define in theinterface
? - 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
andprivate
, like before, but now some items areprotected
. Which items areprotected
, 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 tocalcroot
? - How does the
calcroot
function know to use thediscriminant
variable in its local function? - What would happen if
discriminant
was modified insidecalcroot
? Why is this different than for theroot
variable?
Model 5: 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 6: Declarative Languages - Prolog
Questions
- Describe, in your own words, what this program does.
Model 7: 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 8: 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 9: Programming Constructs in bash
Questions
- What do you think
$1
means? - If
$1
is 5, what is the final value ofx
? - Why was the
\
character necessary in thex=$(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 10: Concurrent and Socket Programming in the Go Language
Concurrency in the Go Language
https://tour.golang.org/concurrency/2Non-Blocking Concurrency Channels in the Go Language
https://gobyexample.com/non-blocking-channel-operationshttps://www.thepolyglotdeveloper.com/2017/05/network-sockets-with-the-go-programming-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?