Advanced Programming [AP-24]

Code 301AA - 9 Credits


LECTURER Andrea Corradini <andrea.corradini@unipi.it>
Timetable Monday 11:00 - 13:00, Room Fib L1
Tuesday 11:00 - 13:00, Room Fib L1
Wednesday 16:00 - 18:00, Room Fib C
Office hours By appointment sending an email to <andrea.corradini@unipi.it>.
Syllabus of the course Syllabus
Recordings of lessons of AY 2021/22 The course is held in presence, and lessons are not recorded. The recordings of the AY 2021/22 are accessible from here

Page permanently under construction...

Course description

See: https://unipi.coursecatalogue.cineca.it/insegnamenti/2024/52756_691454_67343/2012/52756/10434?coorte=2024&schemaid=9087

Evaluation

The final grade is based on the evaluation of the programming assignments that will be proposed along the course, and on a final oral exam. The programming assignments have to be submitted at the very latest ten working days before the oral exam. During the oral exam the lecturer may ask questions about any topic presented during the course as detailed in the Syllabus of the course.

Students who cannot attend the course for valid reasons (e.g. visa problems) can ask the lecturer (as soon as possible, not later than the end of the course) to bring the 2021/22 academic year program, for which they can find the recordings of the lessons on page https://pages.di.unipi.it/corradini/Didattica/AP-21/.

Structure of the Oral Exam

The Oral Exam consists of three parts:
  1. In the first part of the exam (~15 minutes) the student is invited to present one of the topics of the Syllabus, agreed upon with the lecturer. The presentation has to be oral, without the support of slides.
    Typically, a topic is identified by a number (from 1 to 9) and possibly by one or more letters (eg. 2.b [The JVM Instruction Set], or 6.c-d [Type classes and Monads in Haskell]). Introductory topics (like 3.a, 5.a, 9.a) will not be accepted alone.
    In the email proposing the dates for the oral exam (see below) the student has to propose at least two topics among those listed in the syllabus, in decreasing order of preference. The lecturer will make the best effort to assign the preferred topic, unless too many students have chosen the same one.
  2. The second part of the oral exam is dedicated to a discussion about the progamming assignments.
  3. In the third part the lecturer can ask questions about any topic listed in the syllabus.

Exam dates

Students can take the oral exam during the exam sessions, fixing a date with the lecturer. Each student should first register for one of the dates published on the portal https://esami.unipi.it/esami2/, which is only possible after filling the evaluation questionnaire. Next the student should send an email to the lecturer with subject "[AP-24] Oral Exam", proposing some dates for the oral exam (not earlier than ten days after the date of the email) and proposing the topics for the first part of the oral exam, as explained above.
Note: The date of the oral exam can be fixed independently of the date published in the portal, even before that date. In particular, upon request, in January 2025 an oral exam can take place also before 13-01-2025.

Programming assignments

  1. First programming assignment
  2. Second programming assignment

Prerequisites

In order to take full advantage of the course and of being able to pass the final exam in a reasonable time, students are required to have an undergraduate level knowledge of at least one object-oriented programming language (like Java, C++, C# or others) and of at least one functional programming language (like Haskell, OCaml, Scheme or others). Students having a weak background on such topics should inform the lecturer at the beginning of the course, and are strongly encouraged to review by themselves the core notions of Object-Oriented and Functional Programming at the beginning of the course, possibly exploiting the following online material:

For Object-Oriented programming:

For Functional Programming:

Course Schedule

N.
DATE
TOPIC
SLIDES
NOTES
1
Sep. 16, 2024, 11:00-13:00
Presentation of the course Slides: AP-2024-01-CourseOverview.pdf
AP-2024-02-MotivationsIntro.pdf
Students attending the course are asked to fill in this FORM, thanks!
2
Sep. 17, 2024
Syntax, Semantics and Pragmatics
Programming languages and Abstract Machines
Compilation and interpretation schemes
Slides: AP-2024-03-Compilation-Interpretation.pdf Suggested readings: Chapter 1 of Programming Languages: Principles and Paradigms by Maurizio Gabbrielli and Simone Martini

Compiler explorer: http://www.godbolt.org
3
Sep. 18, 2024
The Java Virtual Machine: architecture and runtime data areas. Slides: AP-2024-04-Intro2JVM.pdf,till page 32. Suggested readings: Chapter 7: Run-time Enviroments Section 7.1, 7.2 and 7.4.1-2 of "The Dragon Book"
JVM Internals, by James D. Bloom http://blog.jamesdbloom.com/JVMInternals.html
Chapters 1 and 2 of The Java Virtual Machine Specification, Java SE 17 Edition
4
Sep. 23, 2024
Disassembling class files
The Java Virtual Machine: Initialization and Verification.
The JVM Instruction Set: properties, format and addressing modes.
Slides: AP-2024-04-Intro2JVM.pdf, all.
AP-2024-05-JVM-InstructionSet.pdf, till page 10.
Suggested readings:
JVM Internals, by James D. Bloom http://blog.jamesdbloom.com/JVMInternals.html
Chapters 1 and 2 of The Java Virtual Machine Specification, Java SE 17 Edition
Reference documentation: The Java Language Specification, Java SE 17 Edition
5
Sep. 24, 2024
The JVM Instruction Set, end.
Just In Time compilation in the HotSpot JVM
Slides: AP-2024-05-JVM-InstructionSet.pdf, all. Suggested readings: Section 2.11 and Chapter 3 of The Java Virtual Machine Specification, Java SE 17 Edition
Java Code To Byte Code - Part One, by James D. Bloom, http://blog.jamesdbloom.com/JavaCodeToByteCode_PartOne.html
How the JIT compiler boosts Java performance in OpenJDK, by Roland Westrelin, https://developers.redhat.com/articles/2021/06/23/how-jit-compiler-boosts-java-performance-openjdk
6
Wednesday Sep. 25, 2024, Room C
Exercises: Inspecting Java bytecode and the JVM

You can send your solutions to the lecturer with an email with subject "[AP-24] Solutions to EX 1". Do not send JAR files.

Proposed Exercises: Inspecting the JVM

Instructions: exercises-1-2024.pdf
Other files: WrongQueue.java
For this lesson please be sure to have installed:
Please check that the downloaded software works correctly on your computer.
7
Sep. 30, 2024
Software Components: an introduction Slides: AP-2024-06-SoftwareComponentsIntro.pdf Suggested readings:
Chapter 1 and Chapter 4 of [COMP], Component Software: Beyond Object-Oriented Programming. C. Szyperski, D. Gruntz, S. Murer, Addison-Wesley, 2002.
8
Oct. 1, 2024
Software Components: the Sun approach, JavaBeans
Slides: AP-2024-07.JavaBeans.pdf
Suggested readings:
9
Oct. 2, 2024
Reflection in Java
Annotations in Java
Slides:
AP-2024-08-Reflection.pdf.
Suggested readings:
The Java Tutorial on Reflection API, excluding Arrays and Enumerated Types.
The Java Tutorial on Annotations.
10
Oct. 7, 2024
Frameworks and Inversion of Control Slides: AP-2024-09-IOC.pdf Suggested readings:

11
Oct. 8, 2024
On Designing Software Frameworks Slides: AP-2024-10-DesigningFrameworks.pdf Suggested readings:
12
Oct. 9, 2024
Exercises: Java Beans, Reflection and Annotations
You can send your solutions to the lecturer with an email with subject "[AP-24] Solutions to EX 2". If you want to send a JAR file, change the suffix of the file for example to RAJ, otherwhise GMAIL will block it.
Instructions: exercises_2.html
For this lesson we suggest to use Apache NetBeans.
We will start with a quick look at the Oracle JavaBeans Tutorial
13
Oct. 14, 2024
Polymorphism:
  • A classification
  • Overloading & Coercion
  • Inclusion polymorphism & Overriding
  • Explicit parametric polymorphism: Templates in C++.
Slides:
AP-2024-11-Polymorphism.pdf
AP-2024-12-Templates.pdf (up to page 15)

Compiler Explorer: https://godbolt.org/
(a site for exploring compiled code)

Suggested readings:
14
Oct. 15, 2024
Universal Parametric Polymorphism:
C++ Templates and Java Generics
  • C++ templates
  • Java Generics
  • Bounded type parameters
Slides: AP-2024-12-Templates.pdf (C++ templates) all
AP-2024-13-Generics.pdf (Java Generics) up to page 25.

Compiler Explorer: https://godbolt.org/
(a site for exploring compiled code)

Suggested readings:
15
Oct. 16, 2024
Wildcards in Java
Limitations of Generics.
The Standard Template Library for C++
Slides: AP-2024-13-Generics.pdf (Java Generics), all.
AP-2024-14-STL.pdf (STL).

Suggested readings:
16
Oct. 21, 2024
Introduction to Functional Programming
  • Historical origins
  • Main concepts
  • Language families: LISP, ML, Haskell
  • Core concepts on Haskell
Slides: AP-2024-15-FP.pdf (Functional Programming) Suggested readings:
Students are invited to install the Glasgow Haskell Compiler and Interpreter (GHCI) downloadable from https://www.haskell.org/
17
Oct. 22, 2024
More on Haskell...
  • List comprehension
  • Algebraic Data Types
  • Higher-order functions and combinators
  • Tail Recursion Optimization
  • Converting recursion into Tail Recursion
Slides: AP-2024-16-Haskell2.pdf Suggested readings:
18
Oct. 23, 2024
Exercises on functional programming with Haskell
You can send your solutions to the lecturer with an email with subject "[AP-24] Solutions to EX 3".
Instructions: exercises_3.html

Online documentation of Haskell functions:

Students are invited to install the Glasgow Haskell Compiler and Interpreter (GHCI) downloadable from https://www.haskell.org/downloads/
19
Oct. 28, 2024
  • Lazy evaluation
  • The lambda-calculus: syntax and beta-reduction
  • Church Booleans, Pairs and Numerals, Arithmetics
  • Fixpoint operator and recursion
  • Evaluation orders in lambda-calculus
  • Call by need in Haskell
  • Other parameter passing mechanisms
Slides: AP-2024-17-Lambda.pdf Suggested readings:
20
Oct. 29, 2024
Type classes in Haskell
Type inference
Slides:
AP-2024-18-TypeClasses_inference.pdf, up to page 40.
Suggested readings:
21
Oct. 30, 2023
Type inference
Constructor Classes and Monads in Haskell
Slides:
AP-2024-18-TypeClasses_inference.pdf, all.
AP-2024-19-Monads.pdf, till page 17.
Suggested readings:
 
Nov. 4, 2024
The lesson of Monday, November 4 is canceled because of unavailability of the lecturer
22
Nov. 5, 2024
More on Constructor Classes and Monads in Haskell
Input-Output in Hakell: the IO Monad
Type (un)safety in Haskell: unsafePerformIO
Slides:
AP-2024-19-Monads.pdf, all.
Suggested readings:
23
Nov. 6, 2024
Exercises on Type Classes in Haskell
You can send your solutions to the lecturer with an email with subject "[AP-24] Solutions to EX 4".
Instructions: exercises_4.html

Online documentation of Haskell functions:

Students are invited to install the Glasgow Haskell Compiler and Interpreter (GHCI) downloadable from https://www.haskell.org/downloads/

24
Nov. 11, 2024
Lambda expressions in Java 8 Slides: AP-2024-20-JLambdas.pdf Suggested readings:
25
Nov. 12, 2024
The Stream API in Java 8 Slides: AP-2024-21-JStreams.pdf. Suggested readings:
26
Nov 13, 2024
Exercises on Java Stream API
You can send your solutions to the lecturer with an email with subject "[AP-24] Solutions to EX 5".
Exercises on Java Stream API: exercises_5.html
Students are invited to bring their laptops. Be sure to have installed:
  • Java SE Development Kit (JDK), version >= 8. Suggested version: JDK 21
27
Nov. 18, 2024
The Java Memory Model Slides: AP-2024-22-JavaMemoryModel.pdf. The reading material for the JMM is: [Manson05] Jeremy Manson, William Pugh, and Sarita V. Adve. The Java memory model. In POPL '05: 378-391 [see also here]
Additional material:

28
Nov. 19, 2024
The RUST programming language: An introduction (Part 1) Slides: AP-2024-23-RUST.pdf. Suggested readings from the Rust book:
  • Foreword, Introduction
  • Chapter 1 - Getting Started
  • Chapter 3 - Common Programming Concepts
  • Chapter 4 - Understanding Ownership
29
Nov. 20, 2024
The RUST programming language: An introduction (Part 2) Slides: AP-2024-24-RUST.pdf Suggested readings from the Rust book:
  • Chapter 6 - Enums and Pattern Matching
  • Chapter 10 - Generic Types, Traits and Lifetimes
30
Nov. 25, 2024
The RUST programming language: An introduction (Part 3) Slides: AP-2024-25-RUST.pdf. Suggested readings from the Rust book:
  • Chapter 15 - Smart Pointer
  • Section 19.1 - Unsafe Rust
Nov. 25, 2023
Programming assigments on JavaBeans and Reflection/Annotations in Java. First programming assignment [Suggested deadline: December 20, 2024, flexible]
31
Nov. 26, 2024
An introduction to Python Slides: AP-2024-26-PythonIntro.pdf. Suggested readings:
32
Nov. 27, 2024
Functional programming in Python Slides: AP-2024-27-Python-Functions.pdf. Suggested readings:
33
Dec. 2, 2024
Python: Object Oriented Programming, Encapsulation, Iterators and Generators. Slides: AP-2024-28-Python-OOP.pdf, till page 23 Suggested readings:
34
Dec. 3, 2024
Python: Typing and Polymorphism, Garbage Collection and Memory Safety, the GIL, Builtins and Libraries.
Slides: AP-2024-28-Python-OOP.pdf, all. Suggested readings:
35
Dec. 4, 2024
Exercises on Python
You can send your solutions to the lecturer with an email with subject "[AP-24] Solutions to EX 6".
Exercises Python: exercises_6.html
Auxiliary file: anagram.txt
Students are invited to bring their laptops. Be sure to have installed the Python interpreter, downloadable from:

This is the last lesson of the course

Links