Abstract Types Defined as Classes of Variables

Slides:



Advertisements
Similar presentations
Programming Languages Marjan Sirjani 2 2. Language Design Issues Design to Run efficiently : early languages Easy to write correctly : new languages.
Advertisements

Chapter 7:: Data Types Programming Language Pragmatics
Solutions to Review Questions. 4.1 Define object, class and instance. The UML Glossary gives these definitions: Object: an instance of a class. Class:
Reasons to study concepts of PL
Aalborg Media Lab 21-Jun-15 Software Design Lecture 1 “ Introduction to Java and OOP”
1) More on parameter passing: a) Parameter association b) Default parameters c) Procedures as parameters 2) Modules: Ada packages, C modules, C header.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
Language Evaluation Criteria
PROGRAMMING LANGUAGES The Study of Programming Languages.
Abstract Types Defined as Classes of Variables Jeffrey Smith, Vincent Fumo, Richard Bruno.
C++ Code Analysis: an Open Architecture for the Verification of Coding Rules Paolo Tonella ITC-irst, Centro per la Ricerca Scientifica e Tecnologica
1-1 University of Hail College of Computer Science and Engineering Department of computer Science and Software Engineering Course: ICS313: Fundamentals.
Chapter 3 Introduction to Collections – Stacks Modified
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 CST 221 OBJECT ORIENTED PROGRAMMING(OOP) ( 2 CREDITS.
Features of Object Oriented Programming Lec.4. ABSTRACTION AND ENCAPSULATION Computer programs can be very complex, perhaps the most complicated artifact.
More on Hierarchies 1. When an object of a subclass is instantiated, is memory allocated for only the data members of the subclass or also for the members.
CSE 425: Data Types I Data and Data Types Data may be more abstract than their representation –E.g., integer (unbounded) vs. 64-bit int (bounded) A language.
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
ADT data abstraction. Abstraction  representation of concepts by their relevant features only  programming has two major categories of abstraction process.
Principles of programming languages 10: Object oriented languages Isao Sasano Department of Information Science and Engineering.
Data Design and Implementation. Definitions Atomic or primitive type A data type whose elements are single, non-decomposable data items Composite type.
How to execute Program structure Variables name, keywords, binding, scope, lifetime Data types – type system – primitives, strings, arrays, hashes – pointers/references.
1 CS Programming Languages Class 22 November 14, 2000.
(1) ICS 313: Programming Language Theory Chapter 11: Abstract Data Types (Data Abstraction)
Program Design. Simple Program Design, Fourth Edition Chapter 1 2 Objectives In this chapter you will be able to: Describe the steps in the program development.
Copyright 2006 Pearson Addison-Wesley, 2008, 2012 Joey Paquet 1 Concordia University Department of Computer Science and Software Engineering SOEN6441 –
Chapter 1: Preliminaries Lecture # 2. Chapter 1: Preliminaries Reasons for Studying Concepts of Programming Languages Programming Domains Language Evaluation.
Code: BCA302 Data Structures with C Prof.(Dr.) Monalisa Banerjee By.
Sung-Dong Kim, Dept. of Computer Engineering, Hansung University Java - Introduction.
Applications Active Web Documents Active Web Documents.
Principles of programming languages 10: Object oriented languages
Lecture 1b- Introduction
Advanced Computer Systems
Knowledge Representation Techniques
OOP - Object Oriented Programming
Visit for more Learning Resources
Types CSCE 314 Spring 2016.
Abstract Data Types and Encapsulation Concepts
Type Checking Generalizes the concept of operands and operators to include subprograms and assignments Type checking is the activity of ensuring that the.
SOFTWARE DESIGN AND ARCHITECTURE
C Language VIVA Questions with Answers
Principles of Programming and Software Engineering
Revision Lecture
11.1 The Concept of Abstraction
Inheritance in Java.
JAVA Introduction ការណែនាំពី Java
Lecture 2 of Computer Science II
Modularity and Memory Clearly, programs must have access to memory
PRINCIPALES OF OBJECT ORIENTED PROGRAMMING
Programming Language Concepts (CIS 635)
TIM 58 Chapter 8: Class and Method Design
Interfaces and Inheritance
Your First Java Application
High Level Programming Languages
Polymorphism.
College of Computer Science and Engineering
Engineering Computation with MATLAB
Java Programming Arrays
Advanced Programming Behnam Hatami Fall 2017.
More Object-Oriented Programming
Polymorphism Professor Hugh C. Lauer CS-2303, System Programming Concepts (Slides include materials from The C Programming Language, 2nd edition, by Kernighan.
Names and Binding In Text: Chapter 5.
(Computer fundamental Lab)
Chapter 7 Expressions and Assignment Statements.
Inheritance and Polymorphism
Oriented Design and Abstract Data Type
PRESENTED BY ADNAN M. UZAIR NOMAN
Reasons To Study Programming Languages
11.1 The Concept of Abstraction
Chapter 11 Abstraction - The concept of abstraction is fundamental in
Presentation transcript:

Abstract Types Defined as Classes of Variables D. L. Parnas, J.E. Shore, D.M. Weiss

Abstract Data Types Defining Data Types is Important Scalar types are somewhat consistently defined for a programming language, and are precisely defined for a given compiler and runtime environment. Ex: What is the sizeof(int)? Definition of an abstract data type tends to be less clear Furthermore some clarity is necessary about the differences between a user-defined type and an abstract type This paper is about the definition of what we refer to as a “type” in programming languages

Why is the Definition of Data Types Important? Existing programming languages allow the user to define new types “typedef” in C Classes in Java/C++ Is every user-defined type really a “type” from a programming language perspective? Formal definition of a “type” is necessary Remember the age of this paper and put this paper into modern day perspective

Ways that types have been Defined Syntactic: Type is information given to a variable in its definition Value Space: A type is defined/constrained by a possible set of allowable values Behavior: A type is defined by a value space and a set of operations on the elements in that space Representation: Any type can be defined in terms of the primitive types for which is was defined Representation + Behavior: A type is determined by its representation and the set of operations that defines its behavior. Some of these definitions sound like how we define a class…

The Problem… The proposed definitions fall short Consider the desire for strongly typed languages with a clear and simple set of semantic rules Consider the desire of abstracting the design of code that needs to work with multiple type classes Parnas’ analysis of the previously used definitions resulted in: Exclusion of important practical cases Exceptions that complicated the basic language semantics

Approach for Defining a Type Parnas defines a type as equivalence classes of variables. Variables are considered to be primitive Variables will be used in the definition of mode (class of variable) and type The novelty of Parnas’ approach is based on the observation that a type can be defined in terms of a variable and its permitted contexts.

Why Allow Types to be Extended? Type extension support is not a necessary feature of a programming language – they don’t increase the class of functions that can be computed by a given language – but they are helpful. Abstraction – User defined types provide an abstraction from using an equivalent set of primitive types. Redundancy and Compile Time Checking – Provides more information to the compiler than using primitive types – can help the compiler to produce better code. Abbreviation – User types tend to offer an abbreviated syntax. This simplifies coding making programs easier to build and easier to understand. Portability – Defining user types is a good way to manage portability given that the program may need to be recompiled and executed on different platforms. E.g., Is an int 16 or 32 bits?

Objectives/Goals of Type Extension Support The Existing Definitions Don’t Map to the Goals of Clearly Defining a Data Type Objectives/Goals of Type Extension Support Existing Definitions Syntactic Value Space Behavior Representation Representation + Behavior Abstraction Redundancy + Compile Time Checking Abbreviation Portability ? The mapping ot the existing definitions to the objectives of user-defined types is unclear. Its much clearer for scalar types

Parnas’ Approach for Defining a Type To achieve the goals outlined for defining a type one must consider the situations in which one variable may be substituted for another The existing definitions tend to place restrictions on the context in which variable substitutions are allowed Parnas’ Approach: A variable is considered primitive, and types are defined as various equivalence classes of variables The key to this approach is to clearly define when one variable can be substituted for another variable legally.

Mode of a Variable A mode is a group of variables that are represented and accessed in the same manner Defines an equivalence class on variables. (i.e., Any value that can be stored in a particular variable of a given mode can be stored in any variable of that mode) The mode of a variable provides enough information for the compiler to generate code

Types = Classes of Modes Each mode defines a class of variables Variables that can be substituted for each other in any context will not produce a compile-time error A type is a class of variables that can be substituted for each other in some restricted (compiler defined) contexts Types may consist of more than one mode (mode classes) Supports the goal of writing reusable (type-flexible) code that is strongly type-checked

Abstract Data Types An ADT is a type that includes more than one mode and can deal with all members of the mode class without distinguishing between them Enables developers to write more generic (and possibly more reusable) code Consider templates and polymorphism User Defined Types ≠ Abstract Types ADT are special cases of user-defined types

Conditions for Grouping Modes into Types Grouping modes into types can be useful for solving common programming problems elegantly Spec-Types Rep-Types Param-Types Variant Types

Spec-Types Types consisting of modes with identical externally visible behavior Appropriate for types that can be defined solely on operators allowed on the type. These variable types tend to have a well-defined specification int x = 10; int y = 20; int z = Math.min(x,y); System.out.println (“Min is ” + z); long x = 10; long y = 20; long z = Math.min(x,y); System.out.println (“Min is ” + z);

Rep-Types Types consisting of modes with identical representation Types with identical internal representations are of the same rep-type but may not have the same characteristics when the operators are applied to the representation. Example: Consider booleans in “C”. They are integers, but a boolean with the value 0 or 1 is different from an integer with a value of 0 or 1. Also think about enums, bitmasks, etc. in the “C” language These are some of the reasons why “C” is not considered a type-safe language

Param-Types Mode descriptions can be parameterized The class of all modes that can be obtained by passing type information as a parameter can be considered a type (param-type) Helpful when the goal is code sharing Param-Types enable the same code to work on variables of different types Mode information needs to be parameterized Example: Templates in C++

Variant-Types Variant-Types are types consisting of Modes with some common properties It’s a weaker form of a Spec-Type Enables programs to be written using the common properties of a type, while ignoring the special properties of a given type. Example 1: Inheritance: an object may be treated like any other type defined in its inheritance hierarchy. Example 2: Polymorphism: an object of a specific type may be used interchangeably with an object of another type if they share some common properties, but have different behaviors

Flexibility in Type Definition and Code Sharing Having a flexible definition of type enables various degrees of code sharing: Sometimes the same code can operate on different types (param-types) Sometimes source code can be shared (but not the binaries) since the implementation is machine dependant (spec-types) Sometimes it is necessary for code sharing purposes to determine type information at runtime (not all languages support this – but consider the instanceof() operator in Java).

Summary Defining a type is important for programming language design, and the effective usage of a programming language Consider code reuse At the time of this paper (1975) many of the concepts about typing were not implemented in available programming languages, but many of these concepts are supported in today’s programming languages This paper is another case where Parnas was thinking ahead and his observations have been shown to be “right on”.