1 Advanced Material The following slides contain advanced material and are optional.

Slides:



Advertisements
Similar presentations
Program Verification Using the Spec# Programming System ETAPS Tutorial K. Rustan M. Leino, Microsoft Research, Redmond Rosemary Monahan, NUIM Maynooth.
Advertisements

CPSC 388 – Compiler Design and Construction
Introduction to Linked Lists In your previous programming course, you saw how data is organized and processed sequentially using an array. You probably.
Coding Standard: General Rules 1.Always be consistent with existing code. 2.Adopt naming conventions consistent with selected framework. 3.Use the same.
Today Quiz solutions are posted on the Grading page. Assignment 1 due today, 7pm. Arrays as Pointers, Cont. Aliasing & Passing by Reference null Winter.
6/10/2015C++ for Java Programmers1 Pointers and References Timothy Budd.
Road Map Introduction to object oriented programming. Classes
Avoid a void Bertrand Meyer With major contributions by Emmanuel Stapf & Alexander Kogtenkov (Eiffel Software)
 2006 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
1 Advanced Material The following slides contain advanced material and are optional.
Chair of Software Engineering Avoid a void Bertrand Meyer ©Bertrand Meyer, 2008.
1 Advanced Material The following slides contain advanced material and are optional.
1 Advanced Material The following slides contain advanced material and are optional.
 2006 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
Chair of Software Engineering Automatic Verification of Computer Programs.
Declaring and Checking Non-null Types in an Object-Oriented Language Authors: Manuel Fahndrich K. Rustan M. Leino OOPSLA’03 Presenter: Alexander Landau.
1 Type Type system for a programming language = –set of types AND – rules that specify how a typed program is allowed to behave Why? –to generate better.
Introduction to Classes and Objects CS-2303, C-Term Introduction to Classes and Objects CS-2303 System Programming Concepts (Slides include materials.
1 Types Object Oriented Programming Spring 2007.
Inheritance and Polymorphism CS351 – Programming Paradigms.
Ranga Rodrigo. Class is central to object oriented programming.
Unit Testing & Defensive Programming. F-22 Raptor Fighter.
1-Sep-15 Scala Apologia. 2 Java What’s wrong with Java? Not designed for highly concurrent programs The original Thread model was just wrong (it’s been.
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 13: Pointers, Classes, Virtual Functions, and Abstract Classes.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 14: Pointers, Classes, Virtual Functions, and Abstract Classes.
Assertions Program correctness. Assertions Java statement – enables you to assert an assumption about your program. – An assertion contains a Boolean.
Coding Methodology How to Design Code. © 2005 MIT-Africa Internet Technology Initiative Pay Attention to Detail When implementing or using APIs details.
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
Designing Programming Languages to Improve Software Quality David J. Pearce Software Quality New Zealand, August
EE4E. C++ Programming Lecture 1 From C to C++. Contents Introduction Introduction Variables Variables Pointers and references Pointers and references.
Static and Dynamic Behavior CMPS Power of OOP Derives from the ability of objects to change their behavior dynamically at run time. Static – refers.
Chapter 1: A First Program Using C#. Programming Computer program – A set of instructions that tells a computer what to do – Also called software Software.
CSC3315 (Spring 2009)1 CSC 3315 Programming Languages Hamid Harroud School of Science and Engineering, Akhawayn University
Names Variables Type Checking Strong Typing Type Compatibility 1.
1 Assertions. 2 assertions communicate assumptions about the state of the program, and stop processing if they turn out to be false very often comments.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
Defining and Converting Data Copyright Kip Irvine, 2003 Last Update: 11/4/2003.
410/510 1 of 18 Week 5 – Lecture 1 Semantic Analysis Compiler Construction.
More About Objects and Methods Chapter 5. Outline Programming with Methods Static Methods and Static Variables Designing Methods Overloading Constructors.
Programming in Java CSCI-2220 Object Oriented Programming.
Exceptions and Assertions Chapter 15 – CSCI 1302.
SOEN 343 Software Design Section H Fall 2006 Dr Greg Butler
Fall 2015CISC/CMPE320 - Prof. McLeod1 CISC/CMPE320 Today: –Review declaration, implementation, simple class structure. –Add an exception class and show.
Chapter 5 Classes and Methods II Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition) by S.N. Kamin, D. Mickunas, E.
C H A P T E R T H R E E Type Systems and Semantics Programming Languages – Principles and Paradigms by Allen Tucker, Robert Noonan.
6-Feb-16 Scala Apologia. 2 Java What’s wrong with Java? Not designed for highly concurrent programs The original Thread model was just wrong (it’s been.
CSE 501N Fall ’09 07: Iteration 17 September 2009 Nick Leidenfrost.
13-Jun-16 Scala Apologia. 2 Java What’s wrong with Java? Not designed for highly concurrent programs The original Thread model was just wrong (it’s been.
Object Oriented Programming Lecture 2: BallWorld.
MT311 Java Application Development and Programming Languages Li Tak Sing( 李德成 )
Object Oriented Programming. Constructors  Constructors are like special methods that are called implicitly as soon as an object is instantiated (i.e.
Chair of Software Engineering Void safety these slides contain advanced material and are optional.
Design issues for Object-Oriented Languages
The eclipse IDE IDE = “Integrated Development Environment”
Accessible Formal Methods A Study of the Java Modeling Language
Fall 2017 CISC124 9/18/2018 CISC124 First onQ quiz this week – write in lab. More details in last Wednesday’s lecture. Repeated: The quiz availability.
Pointers and References
The following slides contain advanced material and are optional.
Java Programming Language
Introduction to Classes and Objects
Scala Apologia 1-Jan-19.
Units with – James tedder
Units with – James tedder
Fall 2018 CISC124 2/22/2019 CISC124 Quiz 1 This Week. Topics and format of quiz in last Tuesday’s notes. The prof. (me!) will start grading the quiz.
(Computer fundamental Lab)
Object Oriented Programming in java
Java Modeling Language (JML)
CIS 110: Introduction to Computer Programming
Introduction to Classes and Objects
Presentation transcript:

1 Advanced Material The following slides contain advanced material and are optional.

2 Outline  Void-safety  Problem of void-calls  A solution to void-calls  Attached types  Certified attachment patterns  Object test  Void-safety in other languages For detailed information, see “Avoid a Void: The eradication of null dereferencing”

3 From the inventor of null references I call it my billion-dollar mistake. It was the invention of the null reference in At that time, I was designing the first comprehensive type system for references in an object oriented language (ALGOL W). My goal was to ensure that all use of references should be absolutely safe, with checking performed automatically by the compiler. But I couldn't resist the temptation to put in a null reference, simply because it was so easy to implement. This has led to innumerable errors, vulnerabilities, and system crashes, which have probably caused a billion dollars of pain and damage in the last forty years. By Tony Hoare, 2009

4 Problem of void-calls  Entities are either  Attached: referencing an object  Detached: void  Calls on detached entities produce a runtime error  Runtime errors are bad... How can we prevent this problem?

5 Solution to void-calls  Statically attached: checked at compile time  Dynamically attached: attached at runtime  Consistency: A call f.x (...) is only allowed, if f is statically attached. If f is statically attached, its possible runtime values are dynamically attached.

6 Statically attached entities  Attached types  Types which cannot be void  x: attached STRING  Certified attachment patterns (CAP)  Code pattern where attachment is guaranteed  if x /= Void then x.f end (where x is a local)  Object test  Assign result of arbitrary expression to a local  Boolean value indicating if result is attached  if attached x as l then l.f end

7 Attached types  Can declare type of entities as attached or detachable  att: attached STRING  det: detachable STRING  Attached types  Can call features: att.to_upper  Can be assign to detachable: det := att  Cannot be set to void: att := Void  Detachable types  No feature calls: det.to_upper  Cannot be assign to attached: att := det  Can be set to void: det := Void

8 Attached types (cont.)  Entities need to be initialized  Detachable: void  Attached: assignment or creation  Initialization rules for attached types  Locals: before first use  Attributes: at end of each creation routine  Compiler uses simple control-flow analysis  Types without attachment mark  Currently defaults to detachable  In future will be switched to attached

9 Attached types demo  EiffelStudio settings  Declaration  Error messages

10 Certified attachment pattern (CAP)  Code patterns where attachment is guaranteed  Basic CAP for locals and arguments  Void check in conditional or semi-strict operator  Setter or creation capitalize (a_string: detachable STRING) do if a_string /= Void then a_string.to_upper end ensure a_string /= Void implies a_string.is_upper end

11 CAP demo  Different CAPs for locals and arguments  Void check in contract  Void check in conditional  Setter  Creator

12 Object test  Checking attachment of an expression (and its type)  Assignment to a local  Local is not declared and only available in one branch name: detachable STRING capitalize_name do if attached name as l_name then l_name.to_upper end ensure attached name as n and then n.is_upper end

13 Object test demo  Object test in body  Object test in assertion  Object test to test for type

14 Stable attributes  Detachaed attributes which are never set to void  They are initially void, but once attached will stay so  The basic CAPs work for them as well stable name: detachable STRING capitalize_name do if name /= Void then name.to_upper end

15 Stable demo  Feature annotations  CAP with stable attributes  Assigning to stable attributes

16 Void-safety in other languages: Spec#  Research variant of C#  Adds contracts and non-null types (and more)  Non-null types are marked with ! String s = null; String! s = „abc“; String! s = null;

17 Void-safety in other languages: JML  Research variant of Java  Adds contracts and non-null types (and more)  Types (except locals) are non-null per default String s = null; String s = „abc“; String s = null;