CMSI 386
Practice Midterm Preparation

When

Take this any time, but as soon as possible.

Ground Rules

Since this midterm is for practice only and will not be graded, there are no special rules. It is your responsilbility, however, to prepare for it as you would any real exam, and take the exam on your own under test-like conditions. This will best prepare you for the upcoming final, and maximize the amount of learning of this rather difficult material.

Review of the Course Learning Objectives

Remember the learning objectives from the syllabus:

To meet these objectives throughout the course we will be answering both big picture and low-level questions about languages, language design, and language usage. Sample questions will include:

This is just a tiny number of the questions we can ask. For hundreds more, see Chapter 14 in the textbook.

What We Have Learned So Far

We began the course with an overview of the study of programming languages, a look into a particular problem’s solution in 42 languages, and a look at programming language classification and paradigms.

Then we began our tour of programming language concepts with deep dives into JavaScript and Python. In addition to language history we uncovered and practiced many technical linguistic aspects. Here is a small subset of things we learned:

 JavaScriptPython
First Appeared19951991
DesignerBrendan EichGuido von Rossum
VersionsES2015 and later is “modern” JSPython 2 is legacy but will not die; Python 3 is recommended and much better
Recognized ForFirst-class functions, prototypesWonderful expressiveness
Notable UsesWebapp clients, asychronous serversWeb servers, scripting, data science
Six words or lessThe assembly language of the webEasy to learn and extremely productive
REPLYes (Node)Yes
Runs command line scriptsYesYes
Can be hosted?Yes (in browser, usually)Not designed to be
Typing SystemsDynamic and WeakDynamic and Strong
TypesOnly 7, cannot create moreDozens built-in, user can create infinite number of new types
Distinguishes primitive and reference Types?YesNo, everything is an object
Getting the type of an expressiontypeof (operator, funky)type
Types are....just kind of there, they surface as strings with typeofreally objects!
What’s falsy?undefined, null, false, 0, NaN, empty stringNone, False, numeric 0, empty sequences, empty mappings, instances of classes where __nonzero__ or __len__ return 0 or False.
Objects vs. DictionariesKind of conflated, but there is a built-in MapVery different. Dictionaries have type dict, objects are instances of a class
Objects haveproperties, which can be strings or numbersattributes
Object philosophyPrototypesClasses
Gettersget@property
Can properties be added to existing objects?YesYes
Syntax GroupingCurly bracesIndentation
Statement separator; but language uses weird algorithm to add them if you forget them; if multiple statements on same line, otherwise newline unless inside of delimiters or triple-quoted string literals.
Local variable declarationsDeclare with let or const (legacy var also supported)Just assign to a variable in function; it will be be local unless a nonlocal or global declaration for the identifier preceded it.
Parallel assignment?Through array pattern matchYes (no delimiters needed)
Increment and decrement operators?YesNo!
Multiline stringsDelimited with backticksDelimited with triple quotes
Package Ecosystemnpmpip
Common unit testing frameworkmochapytest

Interested in more comparisons? Check out the the first two columns of this page. Woah, how useful was THAT?!

What other similarities and differences can you think of?

Format of the Exam

The focus of the exam will be to assess your understanding of certain programming language concepts as evidenced by (1) your ability to express them in both JavaScript and Python, and (2) your ability to articulate the similarities and differences between the JavaScript and Python implementations.

Therefore each exam question will describe a scenario, ask for a JavaScript and Python implementation, and ask you for commentary on a specific, notable similarity or difference.

How to Study

One of the best ways to learn is by discovery in the context of working on things you love, especially in small groups, under the guidance of a competent mentor who can identify and help you clean up mistakes. So to prepare, study in small groups and work on practice problems.

IN ADDITION, keep in mind that our (world’s) knowledge culture is far more literary than oral, so YOU ARE STRONGLY ENCOURAGED to read, or reread:

You have to put in the time for effortful self-study. Although the exam is open resources, you will not have time to “look everything up.” Those who come in with a strong comfort level with the material will finish on time. I am assessing your fluency and your proficiency with the material, not your Google-Fu.

A Sample Problem

Write a Python class and a JavaScript “class” implementing a FIFO Queue datatype, backed by the language’s native list or array type, with only (1) methods to add and remove a single item, and (2) a property for the size of the queue. Describe, briefly, the difference in method signatures between the two languages and why they look different.

ANSWER

class Queue:
    def __init__(self):
        self.data = []
    def add(self, item):
        self.data.append(item)
    def remove(self):
        # Horribly slow, but this is what the question asked for, I think
        return self.data.pop(0)
    @property
    def size(self):
        return len(self.data)
class Queue {
  constructor() { this.data = []; }
  add(item) { this.data.push(item); }
  remove() { return this.data.shift(); }
  get size() { return this.data.length; }
}

The Python method signatures include a parameter for the method call’s receiver. This is because Python favors explicitness over implicitness. In JavaScript, the receiver is the implicit expression this so it is not added to the parameter list.