Genericity. Philippe Collet. Master 1 IFI Interna3onal h9p://dep3nfo.unice.fr/twiki/bin/view/minfo/sofeng1314. P.

Size: px
Start display at page:

Download "Genericity. Philippe Collet. Master 1 IFI Interna3onal h9p://dep3nfo.unice.fr/twiki/bin/view/minfo/sofeng1314. P."

Transcription

1 Genericity Philippe Collet Master 1 IFI Interna3onal h9p://dep3nfo.unice.fr/twiki/bin/view/minfo/sofeng1314 P. Collet 1

2 Agenda Introduc3on Principles of parameteriza3on Principles of genericity Genericity in OO languages Sta3c and dynamic genericity Generics in Java 5 P. Collet 2

3 On sofware evolu3on Mastering evolu3on is one of the major challenges of sofware engineering: maintenance cost, quali/es deteriora/on, oversight, bugs Mastering evolu2on consists in: Introducing needed modifica3ons Only needed ones Wherever this is needed Without impairing ini3al quali3es At the lower cost F Difficult Problem especially if the sofware is large and complex P. Collet 3

4 On sofware evolu3on (cont d) A lot of sofware techniques aim at facilita3ng evolu3on management: Avoid duplica3on (uniqueness in defini3on) Hide what is not useful (encapsula3on) Locate and explain dependencies Two families of techniques to manage evolu3on: Planned techniques An3cipate possible evolu3ons, to make them easier and safer Adap2ve techniques «lazy» change handling, one at a 3me, but in the most automa3c way P. Collet 4

5 Planned vs. Adap3ve Planned Parameteriza3on, factoriza3on, genericity, formal models, model- driven engineering Raising the level of abstrac3on, overhead of crea3on should be compensated by ROI Adap3ve Rewri3ng, inheritance, separa3on of concerns, dynamically reconfigurable components Each technique borrows a small part of characteris3cs from the other: There is some planning in inheritance There is some adap3veness in genericity Both techniques complement themselves and can combine with eachother P. Collet 5

6 Principles of parameteriza3on Define a formal parameter of an en3ty, abstract and general, which displays what is necessary and sufficient Subs3tute in an automa3c way formal by effec3ve parameters, with no impact on the use of the formal ones Verify that: Formal parameters are well used (typing) Effec3ve parameters conform to formal ones Usages of generated en33es are coherent P. Collet 6

7 Parameteriza3on on values A value is a simple concept : value + type The formal parameter is typed and hides its poten2al value One can use it and verify its type Effec3ve values can be automa3cally subs3tuted on all occurrences in any document Simple subs3tu3on, macrogenera3on, cpp, sed Checking intensity depends on available knowledge: Nothing: macrogenera3on Classic typing: sta3c checking at compila3on 3me, or at binding and run 3mes Asser3ons, formal specifica3ons: dynamic checking, proofs P. Collet 7

8 Principles of genericity A lot of things are generic: medicines In programming, genericity is a form of type genericity In languages: Impera3ve (pioneer): CLU, LPG, Euclide, Ada OO: Eiffel, then C++, C#, Java This is always a constant search for tradeoffs between: Flexibility in deriva3ons Checking safety Cost at compila3on and run 3mes Simplicity, readability P. Collet 8

9 Generic OO languages Eiffel (pioneer) Powerful and complex mul3ple inheritance Primi3ve types as expanded objects (no limita3ons for genericity) No genericity informa3on at run3me (a simple technique of sta3c typing) Genericity very readable and very simple Constrained genericity through abstract classes Automa3c constraints with like object / like current No introspec3on on effec3ve types P. Collet 9

10 Generic OO languages (2) C++ Macro- genera3on at compila3on or linking 3mes Checking done through the linkers => error messages are strange No constrained genericity (implicit genericity in signatures) No guarantee that the introspec3on of effec3ve types will be possible at run3me P. Collet 10

11 Generic OO languages (3) C# Instan3a3on of generic types at run/me Java Genericity constrainted by class and interface Type checking by the compiler and possible introspec3on at run3me Ten years to put chunks of genericity inside Compa3bility at the code level between generic/non- generic sofware Very sophis3cated, but complex Inconsistencies and performance loss due to compability constraints (cast, type erasure ) Some problems with primi3ve types and arrays P. Collet 11

12 Principles of dynamic genericity An object carries informa3on on its proper3es (through reflexivity) and on its co- instances proper3es The technique is similar to the prototype design pa9ern The formal parameter is an a9ribute of type T All proper3es of T can be used in the model Subs3tu3on is dynamic, by a simple (polymorphic) assignment Possible checking: by dynamic reflexivity, very flexible but costly P. Collet 12

13 Example: polymorphic vector Addi3on of two polymorphic vectors: V1 + V2 = V Ali Baba Ali Baba true false true Advantages: Get more flexibility than with sta3c typing (with which all elements have the same type) No concession on rigorous typing While doing dynamic checking P. Collet 13

14 Solu3on #1 : No sta3c checking All elements are of type Object One checks by introspec3on that two elements of the same index are compa3ble for the addi3on The method «plus» of the first element is used to add the second one This is possible in all OO languages with introspec3on P. Collet 14

15 Solu3on #2: mixed checking, sta3c and dynamic The necessary and sufficient sta3c typing is added to the previous solu3on: All elements are of type Monoid class PolymorphicVector <Monoid> extends ArrayList<Monoid> { } P. Collet 15

16 Solu3on #2: mixed checking, sta3c and dynamic (cont d) One can sta3cally constrain: PolymorphicVector <Number> One can dynamically constrain: class DynamicMonoVector extends ArrayList<Monoid> implements Monoid { Monoid prototype ; // fournit le + Void DynamicMonoVector(Monoid type){ super(); prototype = type; } // Usage DynamicMonoVector pvi = new DynamicMonoVector(new Integer(0)); P. Collet 16

17 Other possibili3es By combining sta3c and dynamic approaches, one has various possibili3es to choose: The degree of polymorphism: all of the same type, same sur- type, same type two by two When the constraint is defined and checked : at compile or run 3mes P. Collet 17

18 Generics in Java 5 The Collec3on Class : Public interface Collection<E> extends Iterable<E> { int size(); boolean isempty(); boolean contains(object o); Iterator<E> iterator(); boolean add(e o); boolean remove(object o); boolean containsall(collection<?> c); boolean addall(collection<? extends E> c); boolean removeall(collection<?> c); boolean retainall(collection<?> c); void clear(); boolean equals(object o); int hashcode(); } P. Collet 18

19 Java 5: generic parameter Declara3on of a formal parameter that will be used throughout the class Use the nota3on <T> just afer the class name Use T in the rest of the code Conven3on: use a capital le9er for the parameter id T will be replaced by a given class at instan3a3on 3me Genericity can be limiter to a specific method: Use the nota3on <T> just before the method signature Use T in the rest of the method code T will be infered from the method argument types P. Collet 19

20 Kinds of generic declara3ons Novariance = Covariance Contravariance : only the specified class is accepted <A> a class A Bivariance = Covariance Contravariance : All classes are accepted <?> joker/unknown any class Covariance (all sub- classes are acceptable) <A extends B> any class A that specializes B (extends, implements) <? extends B> any class that specializes B (extends, implements) Contravariance (all super- classes are acceptable) <? super B> any class that generalizes B P. Collet 20

21 Illustra3ons // Novariance List <Integer> l = new ArrayList <Integer>(); // compilation error: default is novariance // List <Number> l1 = l; // possible : covariance List <? extends Number> l1 = l; // bivariance : typing is lost List <?> l2 = new ArrayList <Object>(); // contravariance List <? super Number> l3 = new ArrayList <Object>(); for (Number n : l1) { // compilation error: l2 could have been a list of Double! // l2.add(n); l3.add(n); // OK } P. Collet 21

22 Illustra3ons (2) // Covariance and contravariance public static <T> void copy(collection <? extends T> src, Collection <? super T> dest) { for(t t : src) { dest.add(t); } } List <Integer> l1 = new ArrayList <Integer>(); for(int i=0; i<10; i++) { l1.add(i); } List <Number> l2 = new ArrayList <Number>(); copy(l1,l2); copy (l2,l1); // Compilation error // Number(s) cannot be put in a list of Integer P. Collet 22

23 Survival guide: PECS principle PECS: Producer extends, Consumer super Use Foo<? extends T> for a producer of T Use Foo<? super T> for a consumer of T Only applicable to method parameters No joker in return types P. Collet 23

24 PECS : applica3on public static <T> void copy(collection<t> src, Collection<T> dest) In copy: src provides elements of type T dest consumes elements of type T public static <T> void copy( Collection <? extends T> src, Collection <? super T> dest) P. Collet 24

25 PECS : applica3on (2) public static <E> Set<E> union(set<e> s1, Set<E> s2) In union: s1 and s2 are producers of elements E! public static <E> Set<E> union(set<? extends E> s1, Set<? extends E> s2) P. Collet 25

26 Type erasure The bytecode understood by a JVM v5 does not contain any trace of genericity due to the constraint of backward compa3bility A Java 5+ compiler: Replace parameters by Object (case of novariance or bivariance) or by the bounded type (co/contra- variance) Create methods with compa3ble signatures for the other cases The problem of return types is solved by the covariance P. Collet 26

27 Conclusions on genericity Genericity allows for factoriza3on and reuse of knowledge and know- how with guaranteed quality Can everything be made generic? NO! The reuse of architectures or canvas to solve a general problem cannot be, most ofen, described by a generic unit. Solu/ons: Design pa9erns Frameworks Domain Specific Languages Dedicated systems (DB, IDE ) SoFware Product Lines P. Collet 27

Java Collection Framework

Java Collection Framework Java Collection Framework Readings Purpose To provide a working knowledge of the Java Collections framework and iterators. Learning Objectives Understand the structure of the Java Collections framework

More information

Encapsula)on, cont d. Polymorphism, Inheritance part 1. COMP 401, Spring 2015 Lecture 7 1/29/2015

Encapsula)on, cont d. Polymorphism, Inheritance part 1. COMP 401, Spring 2015 Lecture 7 1/29/2015 Encapsula)on, cont d. Polymorphism, Inheritance part 1 COMP 401, Spring 2015 Lecture 7 1/29/2015 Encapsula)on In Prac)ce Part 2: Separate Exposed Behavior Define an interface for all exposed behavior In

More information

Object Oriented Design (OOD): The Concept

Object Oriented Design (OOD): The Concept Object Oriented Design (OOD): The Concept Objec,ves To explain how a so8ware design may be represented as a set of interac;ng objects that manage their own state and opera;ons 1 Topics covered Object Oriented

More information

Objec+ves. Review. Basics of Java Syntax Java fundamentals. What are quali+es of good sooware? What is Java? How do you compile a Java program?

Objec+ves. Review. Basics of Java Syntax Java fundamentals. What are quali+es of good sooware? What is Java? How do you compile a Java program? Objec+ves Basics of Java Syntax Java fundamentals Ø Primi+ve data types Ø Sta+c typing Ø Arithme+c operators Ø Rela+onal operators 1 Review What are quali+es of good sooware? What is Java? Ø Benefits to

More information

Why OO programming? want but aren t. Ø What are its components?

Why OO programming? want but aren t. Ø What are its components? 9/21/15 Objec,ves Assign 1 Discussion Object- oriented programming in Java Java Conven,ons: Ø Constructors Ø Default constructors Ø Sta,c methods, variables Ø Inherited methods Ø Class names: begin with

More information

Garbage collec,on Parameter passing in Java. Sept 21, 2016 Sprenkle - CSCI Assignment 2 Review. public Assign2(int par) { onevar = par; }

Garbage collec,on Parameter passing in Java. Sept 21, 2016 Sprenkle - CSCI Assignment 2 Review. public Assign2(int par) { onevar = par; } Objec,ves Inheritance Ø Overriding methods Garbage collec,on Parameter passing in Java Sept 21, 2016 Sprenkle - CSCI209 1 Assignment 2 Review private int onevar; public Assign2(int par) { onevar = par;

More information

Principles of Programming Languages

Principles of Programming Languages Principles of Programming Languages h"p://www.di.unipi.it/~andrea/dida2ca/plp- 14/ Prof. Andrea Corradini Department of Computer Science, Pisa Lesson 18! Bootstrapping Names in programming languages Binding

More information

History of Java. Java was originally developed by Sun Microsystems star:ng in This language was ini:ally called Oak Renamed Java in 1995

History of Java. Java was originally developed by Sun Microsystems star:ng in This language was ini:ally called Oak Renamed Java in 1995 Java Introduc)on History of Java Java was originally developed by Sun Microsystems star:ng in 1991 James Gosling Patrick Naughton Chris Warth Ed Frank Mike Sheridan This language was ini:ally called Oak

More information

Josh Bloch Charlie Garrod Darya Melicher

Josh Bloch Charlie Garrod Darya Melicher Principles of So3ware Construc9on: Objects, Design, and Concurrency Part 2: Class-level design Design paderns for reuse, part 2 Josh Bloch Charlie Garrod Darya Melicher 1 Administrivia Reading due today:

More information

Architecture of so-ware systems

Architecture of so-ware systems Architecture of so-ware systems Lecture 13: Class/object ini

More information

Preliminary ACTL-SLOW Design in the ACS and OPC-UA context. G. Tos? (19/04/2016)

Preliminary ACTL-SLOW Design in the ACS and OPC-UA context. G. Tos? (19/04/2016) Preliminary ACTL-SLOW Design in the ACS and OPC-UA context G. Tos? (19/04/2016) Summary General Introduc?on to ACS Preliminary ACTL-SLOW proposed design Hardware device integra?on in ACS and ACTL- SLOW

More information

An Interface with Generics

An Interface with Generics Generics CSC207 Software Design Generics An Interface with Generics Generics class foo introduces a class with a type parameter T. introduces a type parameter that is required to be

More information

301AA - Advanced Programming [AP-2017]

301AA - Advanced Programming [AP-2017] 301AA - Advanced Programming [AP-2017] Lecturer: Andrea Corradini andrea@di.unipi.it Tutor: Lillo GalleBa galleba@di.unipi.it Department of Computer Science, Pisa Academic Year 2017/18 AP-2018-15: Java

More information

Parametric polymorphism and Generics

Parametric polymorphism and Generics Parametric polymorphism and Generics Today s Lecture Outline Parametric polymorphism Java generics Declaring and instantiating generics Bounded types: restricting instantiations Generics and subtyping.

More information

CSE 331 Software Design & Implementation

CSE 331 Software Design & Implementation CSE 331 Software Design & Implementation Hal Perkins Autumn 2013 Generics (Polymorphism) (Slides by Mike Ernst and David Notkin) 1 Varieties of abstraction Abstraction over computation: procedures int

More information

Agenda. Excep,ons Object oriented Python Library demo: xml rpc

Agenda. Excep,ons Object oriented Python Library demo: xml rpc Agenda Excep,ons Object oriented Python Library demo: xml rpc Resources h?p://docs.python.org/tutorial/errors.html h?p://docs.python.org/tutorial/classes.html h?p://docs.python.org/library/xmlrpclib.html

More information

Charlie Garrod Michael Hilton

Charlie Garrod Michael Hilton Principles of So3ware Construc9on: Objects, Design, and Concurrency Part 1: Designing classes Design pacerns for reuse (con9nued) and design heuris9cs Charlie Garrod Michael Hilton School of Computer Science

More information

301AA - Advanced Programming [AP-2017]

301AA - Advanced Programming [AP-2017] 301AA - Advanced Programming [AP-2017] Lecturer: Andrea Corradini andrea@di.unipi.it Tutor: Lillo GalleBa galleba@di.unipi.it Department of Computer Science, Pisa Academic Year 2017/18 AP-2017-14: Java

More information

Lecture Outline. Parametric Polymorphism and Java Generics. Polymorphism. Polymorphism

Lecture Outline. Parametric Polymorphism and Java Generics. Polymorphism. Polymorphism Lecture Outline Parametric Polymorphism and Java Generics Parametric polymorphism Java generics Declaring and instantiating generics Bounded types: restricting instantiations Generics and subtyping. Wildcards

More information

Objec&ves. Packages Collec&ons Generics. Sept 28, 2016 Sprenkle - CSCI209 1

Objec&ves. Packages Collec&ons Generics. Sept 28, 2016 Sprenkle - CSCI209 1 Objec&ves Packages Collec&ons Generics Sept 28, 2016 Sprenkle - CSCI209 1 PACKAGES Sept 28, 2016 Sprenkle - CSCI209 2 Packages Hierarchical structure of Java classes Ø Directories of directories java lang

More information

Encapsula)on CMSC 202

Encapsula)on CMSC 202 Encapsula)on CMSC 202 Types of Programmers Class creators Those developing new classes Want to build classes that expose the minimum interface necessary for the client program and hide everything else

More information

Ø Interface methods are public by default

Ø Interface methods are public by default Objec+ves Interface/Abstract Class Wrap- up Packaging Collec+ons Generics Javadocs Eclipse Sept 30, 2015 Sprenkle - CSCI209 1 Itera+on over Code Assignment 4 à Assignment 5 Demonstrates typical design/implementa+on

More information

Dynamic Languages. CSE 501 Spring 15. With materials adopted from John Mitchell

Dynamic Languages. CSE 501 Spring 15. With materials adopted from John Mitchell Dynamic Languages CSE 501 Spring 15 With materials adopted from John Mitchell Dynamic Programming Languages Languages where program behavior, broadly construed, cannot be determined during compila@on Types

More information

Effec%ve So*ware. Lecture 9: JVM - Memory Analysis, Data Structures, Object Alloca=on. David Šišlák

Effec%ve So*ware. Lecture 9: JVM - Memory Analysis, Data Structures, Object Alloca=on. David Šišlák Effec%ve So*ware Lecture 9: JVM - Memory Analysis, Data Structures, Object Alloca=on David Šišlák david.sislak@fel.cvut.cz JVM Performance Factors and Memory Analysis» applica=on performance factors total

More information

Chapter 4: Memory. Taylor & Francis Adair Dingle All Rights Reserved

Chapter 4: Memory. Taylor & Francis Adair Dingle All Rights Reserved Chapter 4: Memory Program Memory Overview Analysis of the impact of design on memory use Memory Abstrac9on Heap Memory Memory Overhead Memory Management Programmer s Perspec9ve Standard Views of Memory

More information

Introspec*on and reflexivity

Introspec*on and reflexivity Introspec*on and reflexivity Principles and applica*on to Java Philippe Collet From a Michel Buffa s lecture Master 1 IFI / Interna:onal 2013-2014 h@p://dep:nfo.unice.fr/twiki/bin/view/minfo/sojeng1314

More information

Java's Memory Management

Java's Memory Management Java's Memory Management Oliver W. Layton CS231: Data Structures and Algorithms Lecture 04, Fall 2018 Wednesday September 12 Java %p of the day: Common compila%on errors Class name must MATCH the filename

More information

RDD and Strategy Pa.ern

RDD and Strategy Pa.ern RDD and Strategy Pa.ern CSCI 3132 Summer 2011 1 OO So1ware Design The tradi7onal view of objects is that they are data with methods. Smart Data. But, it is be.er to think of them as en##es that have responsibili#es.

More information

Generic programming POLYMORPHISM 10/25/13

Generic programming POLYMORPHISM 10/25/13 POLYMORPHISM Generic programming! Code reuse: an algorithm can be applicable to many objects! Goal is to avoid rewri:ng as much as possible! Example: int sqr(int i, int j) { return i*j; double sqr(double

More information

RV: A Run'me Verifica'on Framework for Monitoring, Predic'on and Mining

RV: A Run'me Verifica'on Framework for Monitoring, Predic'on and Mining RV: A Run'me Verifica'on Framework for Monitoring, Predic'on and Mining Patrick Meredith Grigore Rosu University of Illinois at Urbana Champaign (UIUC) Run'me Verifica'on, Inc. (joint work with Dongyun

More information

Type Systems. Seman&cs. CMPT 379: Compilers Instructor: Anoop Sarkar. anoopsarkar.github.io/compilers-class

Type Systems. Seman&cs. CMPT 379: Compilers Instructor: Anoop Sarkar. anoopsarkar.github.io/compilers-class Type Systems Seman&cs CMPT 379: Compilers Instructor: Anoop Sarkar anoopsarkar.github.io/compilers-class 1 Equality of types Main seman&c tasks involve liveness analysis and checking equality Equality

More information

What is the Java Collections Framework?

What is the Java Collections Framework? 1 of 13 What is the Java Collections Framework? To begin with, what is a collection?. I have a collection of comic books. In that collection, I have Tarzan comics, Phantom comics, Superman comics and several

More information

Programming Languages and Techniques (CIS120)

Programming Languages and Techniques (CIS120) Programming Languages and Techniques (CIS120) Lecture 20 Feb 29, 2012 Transi@on to Java II DON T PANIC Smoothing the transi@on Eclipse set- up instruc@ons in lab today/tomorrow First Java homework assignment

More information

Array Basics: Outline

Array Basics: Outline Array Basics: Outline More Arrays (Savitch, Chapter 7) TOPICS Array Basics Arrays in Classes and Methods Programming with Arrays Searching and Sorting Arrays Multi-Dimensional Arrays Static Variables and

More information

EDAN65: Compilers, Lecture 13 Run;me systems for object- oriented languages. Görel Hedin Revised:

EDAN65: Compilers, Lecture 13 Run;me systems for object- oriented languages. Görel Hedin Revised: EDAN65: Compilers, Lecture 13 Run;me systems for object- oriented languages Görel Hedin Revised: 2014-10- 13 This lecture Regular expressions Context- free grammar ATribute grammar Lexical analyzer (scanner)

More information

CSCE 314 Programming Languages

CSCE 314 Programming Languages CSCE 314 Programming Languages! Java Generics II Dr. Hyunyoung Lee!!! 1 Type System and Variance Within the type system of a programming language, variance refers to how subtyping between complex types

More information

Generics Collection Framework

Generics Collection Framework Generics Collection Framework Sisoft Technologies Pvt Ltd SRC E7, Shipra Riviera Bazar, Gyan Khand-3, Indirapuram, Ghaziabad Website: www.sisoft.in Email:info@sisoft.in Phone: +91-9999-283-283 Generics

More information

Algorithms. Produced by. Eamonn de Leastar

Algorithms. Produced by. Eamonn de Leastar Algorithms Produced by Eamonn de Leastar (edeleastar@wit.ie) Collections ± Collections Architecture ± Definition ± Architecture ± Interfaces ± Collection ± List ± Set ± Map ± Iterator ± Implementations

More information

CONTAİNERS COLLECTİONS

CONTAİNERS COLLECTİONS CONTAİNERS Some programs create too many objects and deal with them. In such a program, it is not feasible to declare a separate variable to hold reference to each of these objects. The proper way of keeping

More information

Sept 26, 2016 Sprenkle - CSCI Documentation is a love letter that you write to your future self. Damian Conway

Sept 26, 2016 Sprenkle - CSCI Documentation is a love letter that you write to your future self. Damian Conway Objec,ves Javadocs Inheritance Ø Final methods, fields Abstract Classes Interfaces Sept 26, 2016 Sprenkle - CSCI209 1 JAVADOCS Documentation is a love letter that you write to your future self. Damian

More information

Design Pa*erns. Philippe Collet. Master 1 IFI Interna3onal h8p://dep3nfo.unice.fr/twiki/bin/view/minfo/soeeng1213. P.

Design Pa*erns. Philippe Collet. Master 1 IFI Interna3onal h8p://dep3nfo.unice.fr/twiki/bin/view/minfo/soeeng1213. P. Design Pa*erns Philippe Collet Master 1 IFI Interna3onal 2012-2013 h8p://dep3nfo.unice.fr/twiki/bin/view/minfo/soeeng1213 P. Collet 1 Agenda Introduc3on First example Principles and classifica3on Presenta3on

More information

Chapter 6: Structural Design

Chapter 6: Structural Design Chapter 6: Structural Design Class Rela5onships Design alterna,ves for class use and reuse Composi5on Containment Inheritance Code Reuse Design Principles Rela5onships: Containment aka Holds- A subobjects

More information

Generic classes & the Java Collections Framework. *Really* Reusable Code

Generic classes & the Java Collections Framework. *Really* Reusable Code Generic classes & the Java Collections Framework *Really* Reusable Code First, a bit of history Since Java version 5.0, Java has borrowed a page from C++ and offers a template mechanism, allowing programmers

More information

BBM 102 Introduc0on to Programming II Spring 2014

BBM 102 Introduc0on to Programming II Spring 2014 BBM 102 Introduc0on to Programming II Spring 2014 Encapsula0on Instructors: Fuat Akal, Nazlı İkizler Cinbiş, Oğuz Aslantürk TAs: Ahmet Selman Bozkır, Gültekin Işık, Levent Karacan 1 Today Informa0on Hiding

More information

CSE Compilers. Reminders/ Announcements. Lecture 15: Seman9c Analysis, Part III Michael Ringenburg Winter 2013

CSE Compilers. Reminders/ Announcements. Lecture 15: Seman9c Analysis, Part III Michael Ringenburg Winter 2013 CSE 401 - Compilers Lecture 15: Seman9c Analysis, Part III Michael Ringenburg Winter 2013 Winter 2013 UW CSE 401 (Michael Ringenburg) Reminders/ Announcements Project Part 2 due Wednesday Midterm Friday

More information

Lecture 4: Build Systems, Tar, Character Strings

Lecture 4: Build Systems, Tar, Character Strings CIS 330:! / / / / (_) / / / / _/_/ / / / / / \/ / /_/ / `/ \/ / / / _/_// / / / / /_ / /_/ / / / / /> < / /_/ / / / / /_/ / / / /_/ / / / / / \ /_/ /_/_/_/ _ \,_/_/ /_/\,_/ \ /_/ \ //_/ /_/ Lecture 4:

More information

Local defini1ons. Func1on mul1ples- of

Local defini1ons. Func1on mul1ples- of Local defini1ons The func1ons and special forms we ve seen so far can be arbitrarily nested except define and check- expect. So far, defini.ons have to be made at the top level, outside any expression.

More information

CS251 Programming Languages Spring 2016, Lyn Turbak Department of Computer Science Wellesley College

CS251 Programming Languages Spring 2016, Lyn Turbak Department of Computer Science Wellesley College Functions in Racket CS251 Programming Languages Spring 2016, Lyn Turbak Department of Computer Science Wellesley College Racket Func+ons Functions: most important building block in Racket (and 251) Functions/procedures/methods/subroutines

More information

CS101: Fundamentals of Computer Programming. Dr. Tejada www-bcf.usc.edu/~stejada Week 1 Basic Elements of C++

CS101: Fundamentals of Computer Programming. Dr. Tejada www-bcf.usc.edu/~stejada Week 1 Basic Elements of C++ CS101: Fundamentals of Computer Programming Dr. Tejada stejada@usc.edu www-bcf.usc.edu/~stejada Week 1 Basic Elements of C++ 10 Stacks of Coins You have 10 stacks with 10 coins each that look and feel

More information

Component diagrams. Components Components are model elements that represent independent, interchangeable parts of a system.

Component diagrams. Components Components are model elements that represent independent, interchangeable parts of a system. Component diagrams Components Components are model elements that represent independent, interchangeable parts of a system. Components are more abstract than classes and can be considered to be stand- alone

More information

301AA - Advanced Programming [AP-2017]

301AA - Advanced Programming [AP-2017] 301AA - Advanced Programming [AP-2017] Lecturer: Andrea Corradini andrea@di.unipi.it Tutor: Lillo GalleBa galleba@di.unipi.it Department of Computer Science, Pisa Academic Year 2017/18 AP-2017-12: Polymorphisms

More information

Introduction to Python. Fang (Cherry) Liu Ph.D. Scien5fic Compu5ng Consultant PACE GATECH

Introduction to Python. Fang (Cherry) Liu Ph.D. Scien5fic Compu5ng Consultant PACE GATECH Introduction to Python Ph.D. Scien5fic Compu5ng Consultant PACE GATECH Things Covered What is Python? How to access Python environment? Fundamental elements in Python Variables (assignment, comparison,

More information

CSE Lecture 10: Modules and separate compila5on 18 Feb Nate Nystrom University of Texas at Arlington

CSE Lecture 10: Modules and separate compila5on 18 Feb Nate Nystrom University of Texas at Arlington CSE 5317 Lecture 10: Modules and separate compila5on 18 Feb 2010 Nate Nystrom University of Texas at Arlington Modules Key to building large sodware systems is ability to organize the program into modules

More information

Design Principles & Prac4ces

Design Principles & Prac4ces Design Principles & Prac4ces Robert France Robert B. France 1 Understanding complexity Accidental versus Essen4al complexity Essen%al complexity: Complexity that is inherent in the problem or the solu4on

More information

Review. Asser%ons. Some Per%nent Ques%ons. Asser%ons. Page 1. Automated Tes%ng. Path- Based Tes%ng. But s%ll need to look at execu%on results

Review. Asser%ons. Some Per%nent Ques%ons. Asser%ons. Page 1. Automated Tes%ng. Path- Based Tes%ng. But s%ll need to look at execu%on results Review Asser%ons Computer Science 521-621 Fall 2011 Prof. L. J. Osterweil Material adapted from slides originally prepared by Prof. L. A. Clarke Dynamic Tes%ng Execute program on real data and compare

More information

Java: Past, Present, and Future. Brian Goetz Java Language Architect Oracle Corpora>on

Java: Past, Present, and Future. Brian Goetz Java Language Architect Oracle Corpora>on Java: Past, Present, and Future Brian Goetz Java Language Architect Oracle Corpora>on The following is intended to outline our general product direc>on. It is intended for informa>on purposes only, and

More information

Mo#va#ng the OO Way. COMP 401, Fall 2017 Lecture 05

Mo#va#ng the OO Way. COMP 401, Fall 2017 Lecture 05 Mo#va#ng the OO Way COMP 401, Fall 2017 Lecture 05 Arrays Finishing up from last #me Mul#dimensional Arrays Mul#dimensional array is simply an array of arrays Fill out dimensions lef to right. int[][]

More information

Objec,ves. Review: Object-Oriented Programming. Object-oriented programming in Java. What is OO programming? Benefits?

Objec,ves. Review: Object-Oriented Programming. Object-oriented programming in Java. What is OO programming? Benefits? Objec,ves Object-oriented programming in Java Ø Encapsula,on Ø Access modifiers Ø Using others classes Ø Defining own classes Sept 16, 2016 Sprenkle - CSCI209 1 Review: Object-Oriented Programming What

More information

Important Dates. Game State and Tree. Today s topics. Game Tree and Mini-Max. Games and Mini-Max 3/20/14

Important Dates. Game State and Tree. Today s topics. Game Tree and Mini-Max. Games and Mini-Max 3/20/14 MINI-MAX USING TREES AND THE JAVA COLLECTIONS FRAMEWORK Lecture 16 CS2110 Spring 2014 2 Important Dates. April 10 --- A4 due (Connect 4, minimax, trees) April 15 --- A5 due (Exercises on different topics,

More information

Introduc9on to design paderns

Introduc9on to design paderns Principles of So3ware Construc9on: Objects, Design, and Concurrency Designing classes Introduc9on to design paderns Josh Bloch Charlie Garrod School of Computer Science 1 Administrivia Homework 2 due tonight

More information

CSE 331 Software Design and Implementation. Lecture 14 Generics 2

CSE 331 Software Design and Implementation. Lecture 14 Generics 2 CSE 331 Software Design and Implementation Lecture 14 Generics 2 Zach Tatlock / Spring 2018 Big picture Last time: Generics intro Subtyping and Generics Using bounds for more flexible subtyping Using wildcards

More information

COSC 121: Computer Programming II. Dr. Bowen Hui University of Bri?sh Columbia Okanagan

COSC 121: Computer Programming II. Dr. Bowen Hui University of Bri?sh Columbia Okanagan COSC 121: Computer Programming II Dr. Bowen Hui University of Bri?sh Columbia Okanagan 1 Quick Review Representa?ve example: Animal[] mypets = new Animal[4]; mypets[0] = new Dog(); mypets[1] = new Cat();

More information

CSE 331 Software Design and Implementation. Lecture 14 Generics 2

CSE 331 Software Design and Implementation. Lecture 14 Generics 2 CSE 331 Software Design and Implementation Lecture 14 Generics 2 James Wilcox / Winter 2016 Hi, I m James! Big picture Last time: Generics intro Subtyping and Generics Using bounds for more flexible subtyping

More information

Java Generics. Lecture CS1122 Summer 2008

Java Generics.  Lecture CS1122 Summer 2008 Java Generics http://java.sun.com/j2se/1.5/pdf/generics-tutorial.pdf Lecture 17 -- CS1122 Summer 2008 Java Generics quick review When you see in Java, you are dealing with generics Generics allow

More information

Abstract Data Types (ADTs) Example ADTs. Using an Abstract Data Type. Class #08: Linear Data Structures

Abstract Data Types (ADTs) Example ADTs. Using an Abstract Data Type. Class #08: Linear Data Structures Abstract Data Types (ADTs) Class #08: Linear Data Structures Software Design III (CS 340): M. Allen, 08 Feb. 16 An ADT defines a kind of computational entity: A set of objects, with possible values A set

More information

Principles of So3ware Construc9on: Objects, Design, and Concurrency. Designing classes

Principles of So3ware Construc9on: Objects, Design, and Concurrency. Designing classes Principles of So3ware Construc9on: Objects, Design, and Concurrency Designing classes Introduc9on to design paderns, con9nued and Parametric polymorphism (with Java generics) Josh Bloch Charlie Garrod

More information

Programming Languages and Techniques (CIS120)

Programming Languages and Techniques (CIS120) Programming Languages and Techniques (CIS120) Lecture 36 April 23, 2014 Overriding and Equality HW 10 has a HARD deadline Announcements You must submit by midnight, April 30 th Demo your project to your

More information

Programming Languages and Techniques (CIS120)

Programming Languages and Techniques (CIS120) Programming Languages and Techniques (CIS120) Lecture 21 March 17, 2014 Connec@ng OCaml to Java Announcements No Weirich OH today - > Wed 1-3PM instead Read Chapters 19-22 of the lecture notes HW07 available

More information

Outline. Pointers arithme.c and others Func.ons & pointers

Outline. Pointers arithme.c and others Func.ons & pointers Pointers II 1 Outline Pointers arithme.c and others Func.ons & pointers 2 Pointer Arithme/c When you add to or subtract from a pointer, the amount by which you do that is mul/plied by the size of the type

More information

Contents. I. Classes, Superclasses, and Subclasses. Topic 04 - Inheritance

Contents. I. Classes, Superclasses, and Subclasses. Topic 04 - Inheritance Contents Topic 04 - Inheritance I. Classes, Superclasses, and Subclasses - Inheritance Hierarchies Controlling Access to Members (public, no modifier, private, protected) Calling constructors of superclass

More information

boolean add(object o) Method Description (from docs API ) Method Description (from docs API )

boolean add(object o) Method Description (from docs API ) Method Description (from docs API ) Interface Collection Method Description (from docs API ) boolean add(object o) boolean addall(collection c) void clear() ensures that this collection contains the specified element adds all of the elements

More information

Topic #9: Collections. Readings and References. Collections. Collection Interface. Java Collections CSE142 A-1

Topic #9: Collections. Readings and References. Collections. Collection Interface. Java Collections CSE142 A-1 Topic #9: Collections CSE 413, Autumn 2004 Programming Languages http://www.cs.washington.edu/education/courses/413/04au/ If S is a subtype of T, what is S permitted to do with the methods of T? Typing

More information

PIC 20A Collections and Data Structures

PIC 20A Collections and Data Structures PIC 20A Collections and Data Structures Ernest Ryu UCLA Mathematics Last edited: March 14, 2018 Introductory example How do you write a phone book program? Some programmers may yell hash table! and write

More information

Model- Based Security Tes3ng with Test Pa9erns

Model- Based Security Tes3ng with Test Pa9erns Model- Based Security Tes3ng with Test Pa9erns Julien BOTELLA (Smartes5ng) Jürgen GROSSMANN (FOKUS) Bruno LEGEARD (Smartes3ng) Fabien PEUREUX (Smartes5ng) Mar5n SCHNEIDER (FOKUS) Fredrik SEEHUSEN (SINTEF)

More information

A Func'onal Introduc'on. COS 326 David Walker Princeton University

A Func'onal Introduc'on. COS 326 David Walker Princeton University A Func'onal Introduc'on COS 326 David Walker Princeton University Thinking Func'onally In Java or C, you get (most) work done by changing something temp = pair.x; pair.x = pair.y; pair.y = temp; commands

More information

Sets and Maps. Part of the Collections Framework

Sets and Maps. Part of the Collections Framework Sets and Maps Part of the Collections Framework The Set interface A Set is unordered and has no duplicates Operations are exactly those for Collection int size( ); boolean isempty( ); boolean contains(object

More information

Josh Bloch Charlie Garrod Darya Melicher

Josh Bloch Charlie Garrod Darya Melicher Principles of So3ware Construc9on: Objects, Design, and Concurrency Part 2: Class-level design Introduc9on to design paeerns Josh Bloch Charlie Garrod Darya Melicher 1 Administrivia Homework 1 feedback

More information

The plan. Racket will return! Lecture will not recount every single feature of Java. Final project will be wri)ng a Racket interpreter in Java.

The plan. Racket will return! Lecture will not recount every single feature of Java. Final project will be wri)ng a Racket interpreter in Java. Introduc)on to Java The plan Racket will return! Final project will be wri)ng a Racket interpreter in Java. Lecture will not recount every single feature of Java. You may need to do some digging on your

More information

Automated System Analysis using Executable SysML Modeling Pa8erns

Automated System Analysis using Executable SysML Modeling Pa8erns Automated System Analysis using Executable SysML Modeling Pa8erns Maged Elaasar* Modelware Solu

More information

CSE Lecture 7: Polymorphism and generics 16 September Nate Nystrom UTA

CSE Lecture 7: Polymorphism and generics 16 September Nate Nystrom UTA CSE 3302 Lecture 7: Polymorphism and generics 16 September 2010 Nate Nystrom UTA 2 Polymorphism poly = many morph = shape Allow a variable to contain values with different types 3 Subtype polymorphism

More information

Clinical Metadata A complete metadata and project management solu6on. October 2017 Andrew Ndikom and Liang Wang

Clinical Metadata A complete metadata and project management solu6on. October 2017 Andrew Ndikom and Liang Wang A complete metadata and project management solu6on. October 2017 Andrew Ndikom and Liang Wang 1 Agenda How is metadata currently managed within the industry? Five key problems with current approaches.

More information

NAMES, SCOPES AND BINDING A REVIEW OF THE CONCEPTS

NAMES, SCOPES AND BINDING A REVIEW OF THE CONCEPTS NAMES, SCOPES AND BINDING A REVIEW OF THE CONCEPTS Name Binding and Binding Time Name binding is the associa1on of objects (data and/or code) with names (iden1fiers) Shape S = new Shape(); The binding

More information

Array Basics: Outline

Array Basics: Outline Array Basics: Outline More Arrays (Savitch, Chapter 7) TOPICS Array Basics Arrays in Classes and Methods Programming with Arrays Searching and Sorting Arrays Multi-Dimensional Arrays Static Variables and

More information

COSC 121: Computer Programming II. Dr. Bowen Hui University of Bri?sh Columbia Okanagan

COSC 121: Computer Programming II. Dr. Bowen Hui University of Bri?sh Columbia Okanagan COSC 121: Computer Programming II Dr. Bowen Hui University of Bri?sh Columbia Okanagan 1 Quick Review Inheritance models IS- A rela?onship Different from impor?ng classes Inherited classes can be organized

More information

Principles of Programming Languages

Principles of Programming Languages Principles of Programming Languages h"p://www.di.unipi.it/~andrea/dida2ca/plp-16/ Prof. Andrea Corradini Department of Computer Science, Pisa Control Flow Iterators Recursion Con>nua>ons Lesson 25! 1 Iterators

More information

The Java Collections Framework and Lists in Java Parts 1 & 2

The Java Collections Framework and Lists in Java Parts 1 & 2 The Java Collections Framework and Lists in Java Parts 1 & 2 Chapter 9 Chapter 6 (6.1-6.2.2) CS 2334 University of Oklahoma Brian F. Veale Groups of Data Data are very important to Software Engineering

More information

Object Oriented Programming. Feb 2015

Object Oriented Programming. Feb 2015 Object Oriented Programming Feb 2015 Tradi7onally, a program has been seen as a recipe a set of instruc7ons that you follow from start to finish in order to complete a task. That approach is some7mes known

More information

11-1. Collections. CSE 143 Java. Java 2 Collection Interfaces. Goals for Next Several Lectures

11-1. Collections. CSE 143 Java. Java 2 Collection Interfaces. Goals for Next Several Lectures Collections CSE 143 Java Collections Most programs need to store and access collections of data Collections are worth studying because... They are widely useful in programming They provide examples of

More information

Generics method and class definitions which involve type parameters.

Generics method and class definitions which involve type parameters. Contents Topic 07 - Generic Programming I. Introduction Example 1 User defined Generic Method: printtwice(t x) Example 2 User defined Generic Class: Pair Example 3 using java.util.arraylist II. Type

More information

Object Model. Object Oriented Programming Spring 2015

Object Model. Object Oriented Programming Spring 2015 Object Model Object Oriented Programming 236703 Spring 2015 Class Representation In Memory A class is an abstract entity, so why should it be represented in the runtime environment? Answer #1: Dynamic

More information

Collections class Comparable and Comparator. Slides by Mark Hancock (adapted from notes by Craig Schock)

Collections class Comparable and Comparator. Slides by Mark Hancock (adapted from notes by Craig Schock) Lecture 15 Summary Collections Framework Iterable, Collections List, Set Map Collections class Comparable and Comparator 1 By the end of this lecture, you will be able to use different types of Collections

More information

Lecture 15 Summary. Collections Framework. Collections class Comparable and Comparator. Iterable, Collections List, Set Map

Lecture 15 Summary. Collections Framework. Collections class Comparable and Comparator. Iterable, Collections List, Set Map Lecture 15 Summary Collections Framework Iterable, Collections List, Set Map Collections class Comparable and Comparator 1 By the end of this lecture, you will be able to use different types of Collections

More information

Generics with Type Bounds

Generics with Type Bounds Generics with Type Bounds Computer Science and Engineering College of Engineering The Ohio State University Lecture 27 Generic Methods Like classes, methods can be generic class ArrayOps { //ordinary nongeneric

More information

Automa'c Test Genera'on

Automa'c Test Genera'on Automa'c Test Genera'on First, about Purify Paper about Purify (and PurifyPlus) posted How do you monitor reads and writes: insert statements before and a?er reads, writes in code can s'll be done with

More information

Programming Languages and Techniques (CIS120)

Programming Languages and Techniques (CIS120) Programming Languages and Techniques (CIS120) Lecture 27 Mar 23, 2012 Generics, CollecBons and IteraBon Announcements CIS Course Faire TODAY at 3PM, here HW08 is due on Monday, at 11:59:59pm Midterm 2

More information

JCF: user defined collections

JCF: user defined collections JCF: user defined collections Bruce Eckel, Thinking in Java, 4th edition, PrenticeHall, New Jersey, cf. http://mindview.net/books/tij4 jvo@ualg.pt José Valente de Oliveira 20-1 Developing of a user-defined

More information

Proofs about Programs

Proofs about Programs Proofs about Programs Program Verification (Rosen, Sections 5.5) TOPICS Program Correctness Preconditions & Postconditions Program Verification Assignment Statements Conditional Statements Loops Composition

More information

Charlie Garrod Bogdan Vasilescu

Charlie Garrod Bogdan Vasilescu Principles of So3ware Construc9on: Objects, Design, and Concurrency Part 3: Concurrency Introduc9on to concurrency, part 2 Concurrency primi9ves and challenges, con9nued Charlie Garrod Bogdan Vasilescu

More information

Structure Patters: Bridge and Flyweight. CSCI 3132 Summer

Structure Patters: Bridge and Flyweight. CSCI 3132 Summer Structure Patters: Bridge and Flyweight CSCI 3132 Summer 2011 1 Introducing the Bridge Pa1ern Intent To decouple an abstrac7on from its implementa7on so that the two can vary independently. What does it

More information