EECS1015 : a first programming course

This is a proposal for a first programming course for EECS. Currently, the first year courses extend for 12 weeks of 2-hour lecture and 3-hour labs in each week. This may need to be reconsidered.


Rationale

Any choice for a first programming language will be controversial. We propose to use Python3 with type annotations. The following assumptions are all controversial.

  • A main goal is for students to develop high competence in basic computational thinking. See the footnote on computational thinking on the Introduction page. Engagement is a secondary goal, not the primary goal.

  • For beginners, it is better to decouple procedural thinking from object-oriented mechanisms (OO is built on top of procedural constructs). The main part of the first course should focus on procedural constructs free of OO scaffolding that obscures computational thinking. (Simple OO might be introduced right at the end, time permitting)

  • Python3 has a relatively simple and consistent syntax, a large standard library – and using Python in a beginning programming course permits students to concentrate on important programming skills such as loops, procedures (functions and modules), problem decomposition, data type design and testing the correctness of their programs. Type annotations adds significant benefits for checking program correectness. More on python3

  • It is important for the main concepts to be introduced and reinforced. We know that many students entering our second year have problems writing simple loops such as calculating the average of an array of numbers, or adding an element to a linked list. In this introductory course it is crucial that students spend many hours writing, documenting and testing loops for a variety of algorithms. Regular assesment via net secure Labtests is also crucial (given the 3 hour slots for Labs; the last hour might be used for Labtests).

  • In addition to natural ability (and interest), students need to develop the skill of focus and persistence (which takes hard work). This is essential for their academic success. Learning programming involves trial-and-error and thought. This is one of the reasons why competence in programming is likely to be hard for beginners. It is natural to find hours of repeated micro-failures demoralizing. The students who succeed develop coping mechanisms to persist through this learning process. A Computer Science or Software/Computer Engineering major involves deeper topics beyond programming. Some topics may be interesting and easy; whereas others may find the same topics boring and challenging. So they will need persistence to advance whether the topics are of interest or not. The material must of course start gently but must also incrementally challenge students. It's not productive to believe that this first course taken as a whole will be "easy".

For students: About the course

  • Get familiar with the concepts and tools of computer science as you learn a subset of the Python programming language.
  • You do hands-on work to design, write, and test computer programs that solve problems or accomplish tasks.
  • Skills You'll Learn:
    • Designing a program, developing the algorithms it needs, and writing code to implement them
    • Testing program code and correcting errors
    • Documenting and explaining how program code works

Proposed Topics

1. Variables, Primitive Types, Assignment and Sequencing.

Python now has type annotations ansd it should be used in conjunction with the type checker mypy. For primtive types, see below. Later we can also introduce tuples, sets, lists and dictionaries. There is much more to this but in a first course, restrict ourselves to these types.

from typing import List, Set, Dict, Tuple

# For simple built-in types, just use the name of the type
x: int = 1
x: float = 1.0
x: bool = True
x: str = "test"

# For collections, the name of the type is capitalized, and the
# name of the type inside the collection is in brackets
x: List[int] = [1]
x: Set[int] = {6, 7}

# For mappings, we need the types of both keys and values
x: Dict[str, float] = {'field': 2.0}
  • Evaluating arithmetic expressions in program code
  • Using assignment operators to produce a value
  • How variables and operators are sequenced and combined in an expression to create a result

2. Conditionals

  • Logic: Conjunction, Disjunction, Negation etc.
  • Relational: < strictly less than, <= less than or equal, > strictly greater than, >= greater than or equal, == equal, != not equal
  • Nested Conditionals

  • Finding Boolean values with expressions involving relational operators Using conditional statements to execute different statements based on input values

  • Building on conditional statements to create multiple possible outcomes
  • Creating the same value using equivalent Boolean expressions
  • Referencing objects with aliases

At this point, we mau need to introduce siplified models of computation via state machines (or flowcharts) and eventually the heap and the stack.

50% of students entering EEC2030 had trouble with simple conditionals such as checking if a point is in the unit square. (Burton Ma, September 2030). THey had ill-posed conditions such as (x > 1 && x < 0), not realizing that this was nonsensical. These are second year students!

def FindPoint(x1, y1, x2,  y2, x, y) : 
    if x1 <= x <= x2 and y1 <= y <= y2: 
        return True
    else : 
        return False

Here is an annotated typed version of the condition in Python using a typed Dictionary:

'''Check if a point p lies within a rectangle [p1, p2]'''
import typing
from mypy_extensions import TypedDict #experimental

class Point(TypedDict): # not OO, just a record
    x: float
    y: float

def is_contained_point(p, p1, p2: Point) -> bool:
    '''
    p1 is bottom-left and p2 top-right corners of rectangle.
    require
        p1.x <= p2.x and p1.y <= p2.y
    ensure
        Result true iff p is contained in rectangle [p1, p2]
    '''
    if p1['x'] <= p['x'] <= p2['x'] and p1['y'] <= p['y'] <= p2['y']: 
        return True
    else : 
        return False

if __name__ == "__main__" :   # Driver code 
    # rectangle 
    p1: Point = {'x': 0,'y': 0}
    p2: Point = {'x':10,'y': 8}
    # point p
    p: Point =  {'x': 1,'y':5} 
    # function call 
    if is_contained_point(p, p1, p2): 
        print(p, "is contained")  
    else : 
        print(p, "is not contained")  

This prints {'x': 1, 'y': 5} is contained.

The plotting libraries of Python may be used to illustrate the conditional.

3. Debugging and standard I/O

  • The debugger is imnportant for students to understand the model of computation (the heapm the stack, etc)
  • Standard I/O

4. Functions, scoping and abstraction

  • Functions
  • Documentation

5. Unit Testing

  • Unit testing increases confidence in the correctness of the code and changing/maintaining code. If good unit tests are written and if they are run every time any code is changed, we will be able to promptly catch errors introduced due to the change.
  • Works together with debugging
  • Standard I/O

6. Iteration/Loops for algorithms

  • Lists and Intervals (needed for loops)
  • Loops over a linear collection (termination guaranteed),
  • Loops with a condition (that may not terminate).

  • Creating a loop to run an expression repeatedly until certain conditions are met.

  • Termination
  • Representing iterative processes in code using for loops
  • Nesting loop and iteration statements

An example of the kind of loops (and their specification) that students shall be able to write at the end of the course is shown here.

7. Assertions and Specifications

  • Assertions and Exceptions
  • Comments and Documentations
  • Preconditions and Postconditions (see iteration example)
  • More algorithms with iteration

8. More Data Structures: tuples, lists, dictionaries

  • More algorithms with these data structures under unit testing

9. Recursion vs. Iteration

10. Applications

  • Simple git (no branching)
  • E.g. Use Python to visualize data (see the Guttag text). Chosen by instructor.

Course Learning Outcomes

TBD