Docsity

Programming Languages and Techniques (CIS1200) Lecture 39 Recap, Study notes of Algorithms and Programming

Partial preview of the text

Download Programming Languages and Techniques (CIS1200) Lecture 39 Recap and more Study notes Algorithms and Programming in PDF only on Docsity!

Programming Languages

and Techniques

(CIS1200)

Lecture 39

Semester Recap

Announcements

• HW9: Game Project

– Final Program Due: Monday, December 12

th

at

11:59pm

– Grade based on demo with your TA during/after

reading days

– NO LATE SUBMISSIONS PERMITTED

Exam Preparation

• Comprehensive exam covering the entire course:

– Ideas from OCaml material (but no need to write

OCaml)

– All Java material

(emphasizing material since midterm 2)

– All course content except Lecture 33 (Code is Data),

Lecture 38 (Advanced Java), and Lecture 40 (Guest

Lecture)

• Closed book, but…

– You may use one letter-sized, two-sided, handwritten

sheet of notes during the exam.

Monday’s Lecture

Designing OCaml to be predictably faster at Jane Street

Speakers: Richard Eisenberg and Will Goeller, Jane Street

Abstract: Jane Street uses OCaml programs to power millions of

market transactions daily. These programs must be fast, and

their performance must be consistent. The way polymorphism is

designed in OCaml makes predictable high performance hard to

achieve. This talk will explain why this is so, and how we plan to

fix it by extending the language and compiler. Along the way,

we'll see how careful study of programming languages yields

tangible results in a practical setting. The talk will conclude with

information about how OCaml is used at Jane Street and some of

the exciting opportunities there.

From Day 1

  • CIS 1200 is a course in program design
  • Practical skills:
    • ability to write larger (~1000 lines) programs
    • increased independence ("working without a recipe")
    • test-driven development, principled debugging
  • Conceptual foundations:
    • common data structures and algorithms
    • several different programming idioms
    • focus on modularity and compositionality
    • derived from first principles throughout
  • It will be fun! Promise: A challenging but rewarding course.

CIS 1200 Concepts

13 concepts in 36 lectures

Concept: Design Recipe

1. Understand the problem

What are the relevant concepts and how do they relate?

2. Formalize the interface

How should the program interact with its environment?

3. Write test cases

How does the program behave on typical inputs? On unusual ones? On erroneous ones?

4. Implement the required behavior

Often by decomposing the problem into simpler ones and applying the same recipe to each "Solving problems", wrote Polya, "is a practical art, like swimming, or skiing, or playing the piano: You can learn it only by imitation and practice."

Testing

  • Concept: Write tests before coding
    • "test first" methodology
  • Examples:
    • Simple assertions for declarative programs (or subprograms)
    • Longer (and more) tests for stateful programs / subprograms
    • Informal tests for GUIs (can be automated through tools)
  • Why?
    • Tests clarify the specification of the problem
    • Helps you understand the invariants
    • Thinking about tests informs the implementation
    • Tests help with extending and refactoring code later
    • Industry practice; useful for coordinating teams

Functional/Procedural Abstraction

  • Concept: Don't Repeat Yourself!
    • Generalize code so it can be reused in multiple situations
  • Examples: Functions/methods,

generics, higher-order functions,

interfaces, subtyping, abstract classes

inner classes

  • Why?
    • Duplicated functionality = duplicated bugs
    • Duplicated functionality = more bugs waiting to happen
    • Good abstractions make code easier to read, modify, maintain

Concept: Tree Structured data

  • Lists (i.e. “unary” trees)
  • Simple binary trees
  • Trees with invariants: e.g. binary

search trees

  • Widget trees: screen layout + event

routing

  • Swing components
  • Trees are ubiquitous in

computer science!

  • file system organization
  • languages, compilers
  • domain name hierarchy www.google.com
  • Why?
  • organized data leads to divide and conquer algorithms that are more efficient let rec length (l:int list) : int = begin match l with | [] - > 0 | _::tl - > 1 + length(tl) end

First-class computation

  • Concept: code is a form of data that can be defined by

functions, methods, or objects (including anonymous ones),

stored in data structures, and passed to other functions

  • Examples: map, filter, fold (HW4), pixel transformers (HW6),

event listeners (HW5, 7, 9)

  • Why?
    • Powerful tool for abstraction: can factor out design patterns that differ only in certain computations cell.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { selectCell(cell); } }); cell.addMouseListener(e - > selectCell(cell));

Mutable data

  • Concept: Some data structures are ephemeral : computations

mutate them over time

  • Examples: queues, deques (HW4), GUI state (HW5, 9),

arrays (HW 6), dictionaries (HW8)

  • Why?
    • Common in OO programming, which simulates the transformations that objects undergo when interacting with their environment
    • Heavily used for event-based programming, where different parts of the application communicate via shared state
    • Default style for Java libraries (collections, etc.)

Sequences, Sets, Maps

  • Concept: Specific collection types: sequences, sets , and finite

maps

  • Examples: HW3, Java Collections, HW 7, 8
  • Why?
    • These abstract data types come up again and again
    • Need aggregate data structures (collections) no matter what language you are programming in
    • Need to be able to choose the data structure with the right semantics filter map (transform) fold (reduce)