Lecturers: Hesam Setareh Salar Moarref 1 Fall 2009 – Programming languages.

Slides:



Advertisements
Similar presentations
OO Programming in Java Objectives for today: Overriding the toString() method Polymorphism & Dynamic Binding Interfaces Packages and Class Path.
Advertisements

Programming Paradigms Introduction. 6/15/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L1:
Chapter 8 High-Level Programming Languages. 8-2 Chapter Goals Describe the translation process and distinguish between assembly, compilation, interpretation,
OOP - Object Oriented Programming Object Oriented Programming is an approach to programming that was developed to make large programs easier to manage.
Georgia Institute of Technology Workshop for CS-AP Teachers Chapter 3 Advanced Object-Oriented Concepts.
Object Oriented Programming Chapter 7 Programming Languages by Ravi Sethi.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. slide 1 CS 125 Introduction to Computers and Object- Oriented Programming.
High-Level Programming Languages
Reasons to study concepts of PL
ISBN Chapter 1 Preliminaries. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.1-2 Chapter 1 Topics Motivation Programming Domains.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. slide 1 CS 125 Introduction to Computers and Object- Oriented Programming.
Principles of Object-oriented Programming Programming Language Paradigms August 26, 2002.
Aalborg Media Lab 23-Jun-15 Inheritance Lecture 10 Chapter 8.
Run time vs. Compile time
Object-Oriented Databases
Programming Languages Structure
ISBN Lecture 01 Preliminaries. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.1-2 Lecture 01 Topics Motivation Programming.
Object-oriented Programming Concepts
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
ISBN Chapter 1 Topics Motivation Programming Domains Language Evaluation Criteria Influences on Language Design Language Categories Language.
C++ fundamentals.
A First Program Using C#
Programming Languages and Paradigms Object-Oriented Programming.
An Introduction to Smalltalk First Pure Object Oriented Language MacLennan, Chapter 12 Thanks to: Misagh Bagherian S.Jalal Kazemitabar Emad Livani University.
C++ Object Oriented 1. Class and Object The main purpose of C++ programming is to add object orientation to the C programming language and classes are.
REFACTORING Lecture 4. Definition Refactoring is a process of changing the internal structure of the program, not affecting its external behavior and.
C++ Programming. Table of Contents History What is C++? Development of C++ Standardized C++ What are the features of C++? What is Object Orientation?
High-Level Programming Languages: C++
GENERAL CONCEPTS OF OOPS INTRODUCTION With rapidly changing world and highly competitive and versatile nature of industry, the operations are becoming.
MT311 Java Application Development and Programming Languages Li Tak Sing( 李德成 )
OOPs Object oriented programming. Based on ADT principles  Representation of type and operations in a single unit  Available for other units to create.
(1.1) COEN 171 Programming Languages Winter 2000 Ron Danielson.
Sadegh Aliakbary Sharif University of Technology Fall 2011.
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
CS 363 Comparative Programming Languages
Adapted from Prof. Necula UCB CS 1641 Overview of COOL ICOM 4029 Lecture 2 ICOM 4029 Fall 2008.
University of Houston-Clear Lake Proprietary© 1997 Evolution of Programming Languages Basic cycle of improvement –Experience software difficulties –Theory.
11 Chapter 11 Object-Oriented Databases Database Systems: Design, Implementation, and Management 4th Edition Peter Rob & Carlos Coronel.
The Procedure Abstraction, Part V: Support for OOLs Comp 412 Copyright 2010, Keith D. Cooper & Linda Torczon, all rights reserved. Students enrolled in.
Computer Concepts 2014 Chapter 12 Computer Programming.
Guided Notes Ch. 9 ADT and Modules Ch. 10 Object-Oriented Programming PHP support for OOP and Assignment 4 Term project proposal C++ and Java Designer.
Introduction to Object Oriented Programming CMSC 331.
C++ Programming Basic Learning Prepared By The Smartpath Information systems
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
Ch Ch jcmt CSE 3302 Programming Languages CSE3302 Programming Languages (notes, notes, notes) Dr. Carter Tiernan.
CSE 341, S. Tanimoto Java brief review - 1 Java Brief Review Java’s strengths Object-oriented terminology Inheritance Interfaces An example with inheritance.
Summing Up Object Oriented Design. Four Major Components: Abstraction modeling real-life entities by essential information only Encapsulation clustering.
Programming Paradigms Lecturer Hamza Azeem. What is PP ? Revision of Programming concepts learned in CPLB Learning how to perform “Object-Oriented Programming”
Chapter 10, Slide 1 ABSTRACT DATA TYPES Based on the fundamental concept of ABSTRACTION:  process abstraction  data abstraction Both provide:  information.
Salman Marvasti Sharif University of Technology Winter 2015.
Object-Oriented Programming Chapter Chapter
(1) ICS 313: Programming Language Theory Chapter 12: Object Oriented Programming.
OOPs Object oriented programming. Abstract data types  Representationof type and operations in a single unit  Available for other units to create variables.
ISBN Object-Oriented Programming Chapter Chapter
Principles of programming languages 10: Object oriented languages Isao Sasano Department of Information Science and Engineering.
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
Java Programming, Second Edition Chapter Twelve Advanced Inheritance Concepts.
Chapter 11: Advanced Inheritance Concepts. Objectives Create and use abstract classes Use dynamic method binding Create arrays of subclass objects Use.
Sadegh Aliakbary Sharif University of Technology Fall 2010.
ISBN Chapter 12 Support for Object-Oriented Programming.
Chapter 5 Introduction to Defining Classes Fundamentals of Java.
Sung-Dong Kim, Dept. of Computer Engineering, Hansung University Java - Introduction.
Principles of programming languages 10: Object oriented languages
OOP - Object Oriented Programming
7.1 What Is An Object Object-oriented program - Description or simulation of application Object-oriented programming is done by adopting or extending an.
Computer Programming.
Aaron Bloomfield CS 415 Fall 2005
Object Oriented Programming
Parameter Passing Actual vs formal parameters
ICOM 4029 Fall 2003 Lecture 2 (Adapted from Prof. Necula UCB CS 164)
Presentation transcript:

Lecturers: Hesam Setareh Salar Moarref 1 Fall 2009 – Programming languages

Topics History and Motivation Structural Organization Classes and Subclasses Message Sending Implementation Object-Oriented extensions Evaluation and Epilog 2

History and Motivation Alan Kay at the University of Utah in the late 1960s, suggested that it is possible to put the power of a room-sized, million dollar computer into a package. (Personal Computer) Personal computer needs a personal programming language. Older languages were designed for the scientific and commercial applications that occupy large computers. Kay designed a simulation and graphic-oriented programming language for nonspecialists. 3

History and Motivation Kay is a member of FLEX designer team. FLEX took the ideas of classes and objects from Simula. Kay wanted to provide a rich interactive environment for nonspecialists. Xerox came in: In the 1971 Xerox produced a personal computer, called Dynabook. 4

The born of Smalltalk Smalltalk first version, Smalltalk-72, was designed and implement for Dynabook by Smalltalk-74, Smalltalk-76, Smalltalk-78, and Smalltalk-80 are other versions of it. 5

Topics History and Motivation Structural Organization Classes and Subclasses Message Sending Implementation Object-Oriented extensions Evaluation and Epilog 6

In Smalltalk everything is object, including variables, numbers, strings, etc. For example : x*2 Any object has two major parts: 7 Properties (Variables) Behaviors (Methods) Properties (Variables) Behaviors (Methods) Structural Organization

Scribe 8 Example

Scribe 9 Scribe go:300. Example

Scribe 10 Scribe go:300. Scribe turn:90. Example

Scribe 11 Scribe go:300. Scribe turn:90. Scribe go:300. Example

Scribe 12 Scribe go:300. Scribe turn:90. Scribe go:300. Scribe turn:90. Example

Scribe 13 Scribe go:300. Scribe turn:90. Scribe go:300. Scribe turn:90. Scribe go:300. Example

Scribe 14 Scribe go:300. Scribe turn:90. Scribe go:300. Scribe turn:90. Scribe go:300. Scribe turn:90. Example

Scribe 15 Scribe go:300. Scribe turn:90. Scribe go:300. Scribe turn:90. Scribe go:300. Scribe turn:90. Scribe go:300. Example

Scribe 16 Scribe go:300. Scribe turn:90. Scribe go:300. Scribe turn:90. Scribe go:300. Scribe turn:90. Scribe go:300. Scribe turn:90 Example

Scribe 17 Scribe go:300. Scribe turn:90. Scribe go:300. Scribe turn:90. Scribe go:300. Scribe turn:90. Scribe go:300. Scribe turn:90 4 timesRepeat: [Scribe go:300. Scribe turn:90] Example

Class A class is a plan, which objects are made from. Getting a new object from a class is called instantiation. 18 anotherScribe ← pen

shape|| scribe penup;goto:loc;turnTo:tilt;pendn. 4 timesRepeat: [scribe go:size;turn:90] show || scribe color ink. self shape erase || scribe color background. self shape grow: amount || self erase. size ← size+amount. self show Class Definition 19 class namebox Instance variable nameLoc tilt size scribe Instance message and methods

newAt:initialLocation|newBox| newBox ← self new. newBox setLoc:initialLocation tilt:0 size:100 scribe:pen new. newBox show. ↑ newBox shape|| scribe penup;goto:loc;turnTo:tilt;pendn. 4 timesRepeat: [scribe go:size;turn:90] Class Definition 20 class namebox Instance variable nameLoc tilt size scribe Instance message and methods class message and methods

Topics History and Motivation Structural Organization Classes and Subclasses Message Sending Implementation Object-Oriented extensions Evaluation and Epilog 21

Classes and Subclasses Smalltalk objects model Real-World! Some of objects have similar properties and behaviors. We can group classes of these objects and make superclass which has common variables and methods. 22 dispayObject boxpenwindow

Classes and Subclasses 23 class namebox Instance variable name displayObject Instance message and methods superclass Loc tilt size scribe

Classes and Subclasses A Superclass can be subclass of another class. 24 dispayObject boxpenwindow number… Object …

print || ↑ realPt print + “+” imagePt print + “i” Classes and Subclasses 25 class namecomplex Instance variable namerealPt imagePt Instance message and methods Subclasses can change the inherent method, this process is called Overriding

An Important Issue In Smalltalk a class can’t have several superclass. But, in the Real-World, an object can inherent from more than one object. 26 dispayObject box penbumper numberinventoryItem Object roof door

An Important Issue 27 dispayObject brakeenginebumper numberinventoryItem Object roof door

A simple solution 28 dispayObject box penbumper number inventoryItem Object roof door … ! !

AfricanS.AmericanN.American Another aspect of that issue The way of classification causes class grouping. It is possible for some classes to have several ways of classification. Orthogonal classification: 29 Pets Beasts of burden Source of food Pests

Multiple Inheritance raises difficult problem Multiple inheritance allows a class to be an immediate subclass of more than one class. It solve one problem but, brings many new problems. 30 C B A

Topics History and Motivation Structural Organization Classes and Subclasses Message Sending Implementation Object-Oriented extensions Evaluation and Epilog 31

Dynamic versus Static, Strong versus weak Smalltalk uses dynamic type checking like LISP. Pascal and Ada use static type checking. Dynamic type checking does not imply weak type. 32

Forms of Message Template (Argument Passing) Message sending syntaxes:  Object_namemethodname  Object_namemethodname : argument  Object_namemethodname : 1 st arg 2 nd arg_name:2 nd arg_val We have a problem with arithmetic expression: (x+2)*y (x plus : 2) times : y It became possible for one-parameter message to use an operation. 33

run || Keyboard read eval print The Smalltalk main loop is written in Smalltalk 34 class nameuserTask Instance message and methods Smalltalk is in a loop: read a command, execute the command, print the result and loop true whileTrue: [Display put: user run]

run || sched map: [: Task | Task run] Concurrency is easy to implement 35 class namescheduler Instance message and methods Sched is the name of a set that contains all of the objects that are scheduled to be run concurrently. S map: B, apply block B to every element of S.

Topics History and Motivation Structural Organization Classes and Subclasses Message Sending Implementation Object-Oriented extensions Evaluation and Epilog 36

Implementation: Classes and objects Most of Smalltalk system is written in smalltalk Compiler, decompiler, debugger, editors,… 97% most of implementation data structures are smalltalk objects Smalltalk-80 VM:not portable 6~12KB assembly code One man-year to produce a fully debuged version 37

Implementation Smalltalk Virtual machine: Storage manager Encapsulate the representation of objects and organization of memory Fetch the class of an object Fetch and store the fields of objects Create new objects Interpreter Primitive subroutines 38

Implementation Smalltalk Virtual machine: Storage manager Interpreter Manager for methods Primitive subroutines Collection of methods For performance reasons are implemented in machine code basic I/O functions, integer arithmetic, basic screen graphics functions 39

Implementation There are three central ideas in Smalltalk Objects Classes Message sending 40

Object representation Representation of an object must contain just that information that varies from object to object Instance variables The information stored with the class includes the class methods and instance methods 41

Representation of objects Len6 c.d. loc Tilt Size scribe Len6 c.d. Loc Tilt Size Scribe Len4 c.d. X Y Box point 42

Class representation everything in Smalltalk is an object Even classes! Classes are instances of the class named class Instances variables of a class object contain pointers to objects representing the information that is the same for all instances of the class What is this information? 43

Representation of class object Len8 c.d. name Super class Inst. Vars Class msgs. Inst. Msgs. Inst. Size4 class “box” DisplayObject “loc tilt size scribe” Message dict 44

Representation of class object(continued) inst. Size  number of instance variables Needed by storage manager when it instantiates an object Message dictionaries A method identified by the keywords Scribe go:100  go: identifies the method Spinner newAt: rate:1  newAt:rate: is method Message template For each message template acceptable to a class or its instances, one of the message dictionaries must contain an entry 45

Message dictionary How should method be represented? Too much slow if the interpreter had to decode the source form every time the method was executed Compile the code into some form of pseudo code that can be rapidly interpreted The source form is needed for editing and displaying class definition Message dictionaries contain two entries for each message template 46

Example of message dictionary. msgmethodsource. Message dictionary “grow:” “grow: amount || self release. Size<- size+amount. Self show” Push ‘slef’ Send ‘erase’,0 Pop Push ‘size’ Push ‘amount’ Send ‘+’,1 Send ‘<-’,1 pop method 47

Implementation of message sending There is a strong resemblance between message passing in Smalltalk and procedure calls in other languages Activation records: primary vehicle for procedure implementation The same is the case in Smalltalk Activation records hold all of the information relevant to one activation of a method 48

Structure of an activation record Environment part The context to be used for execution of the method Instruction part The instruction to be executed when this method is resumed Sender part The activation record of the method that sent the message invoking this method 49

Instruction part Must designate a particular instruction in a particular method Methods are themselves objects  instances of class method Two coordinate system is used for identifying instructions: An object pointer defines the method-object A relative offset identifies the particular instruction within the method object 50

Environment part Local environment Parameters to method Temporary variables Hidden temporary variables such as the intermediate results of expressions Nonlocal environment: all other visible variables Instance variables Class variables 51

Parts of an activation record locals parameters Temporary vars intermediates Non localsStatic link Instruction part method instruction Sender partDynamic link Length c.d. Instance vars instance Length c.d. Superclass Class variable Class Length c.d. Superclass Super class variables 52

Message sending create an activation record for the receiver (callee) Identify the method being invoked by extracting the template form from the message and then looking it up in the message dictionary for the receiving object’s class or super class Transmit the parameters to the receiver’s activation records Suspend the sender(caller) by saving its state in its activation record. Establish a path(dynamic link) from the receiver back to the sender and establish the receiver’s activation record as the active one 53

Returning from a method transmit the returned object(if any) from the receiver back to sender Resume execution of the sender by restoring its state from its activation record 54

Returning from a method transmit the returned object(if any) from the receiver back to sender Resume execution of the sender by restoring its state from its activation record deallocation of the activation record??? The storage manager handles allocation and deallocation of all objects, this include AR objects We don’t explicitly deallocate activation records Smalltalk doesn’t allocate its activation records on a stack concurrency 55

Topics History and Motivation Structural Organization Classes and Subclasses Message Sending Implementation Object-Oriented extensions Evaluation and Epilog 56

Object oriented extensions Many languages have been extended for object oriented programming Fifth generation languages such as LISP Third and fourth generation languages such as C and Ada83 Simula-67 is essentially an object-oriented extension to algol- 60 Programming by extension Suggested by object oriented languages Ability to extend and refine software systems without needing to recompile and retest the parts already implemented 57

Tagged types support programming by extension-Ada Package Display_Objects is type display_object is tagged [private] record loc: display_location; end record; Procedure Go_to ( The_object: display_object; new_loc: display_location); Procedure Show ( The_object:display_object); Procedure Erase ( The_object:display_object); End display_objects; 58

Tagged types support programming by extension-Ada With display_objects; Package Boxes is type Box is new display_objects.display_object with [private] record tilt, size :float; The_scribe: scribe; end record; procedure shape (The_Box: Box);. End Boxes; 59

Package All_Display_Objects type Display_Object is tagged private; … operations for Display_Object … type Box is new Display_Object with private; … operations for Box … type Window is new Display_Object with private; … operations for Window … …etc. … end All_Display_Objects 60 Types and Their Refinements Can be Defined is a Single Package

Abstract declarations in display_object: Procedure shape (The_object: display_Object) is abstract; In Box: Procedure shape (The_box:Box); In package body for display_objects: procedure show(The_object: display_object) is Begin Set_color(The_object); Shape(The_object); End show; 61

Ada’s support for object oriented programming is complex The complexity comes from grafting the object oriented features onto a type system that was designed for different trade-offs(e.g. efficiency on small embedded computers) 62

C++ extends C for object-oriented programming C++ is largely the work of Bjarne Stroustrup C++ supports: Class declaration Multiple inheritance Virtual  abstract in Ada Template  generic in Ada 63

Java is a more advanced object- oriented language derived from C Designed for networked and distributed programming environments Greater emphasis on security, robustness, machine independence, portability Java emits some C++ features: operator overloading, pointers,… Add others such as automatic garbage collection 64

Topics History and Motivation Structural Organization Classes aMessage Sending nd Subclasses Implementation Object-Oriented extensions Evaluation and Epilog 65

Evalution and epilog Smalltalk is small, flexible, and extensible Small, simple, regular language Small number of independent concepts  easy to learn Has demonstrated its flexibility by being Used in a number of applications: simulations, graphics, artificial intelligence Design of Smalltalk has been dictated by several powerful principles: simplicity, regularity, abstraction, security and information hiding 66

Evalution and epilog Smalltalk is an example of a programming environment Has introduced important ideas other than language itself, like widows Is also an excellent example of an advanced programming environment Integration of graphics, windows and an advanced language 67

Evalution and epilog Smalltalk introduces a new programming paradigm Although most of its ideas have appeared in other languages, smalltalk’s integration of these ideas is novel The essence of the Smalltalk view is that programming is simulation  programs model, sometimes in a very abstract form, some aspects of the real world 68

Evalution and epilog Smalltalk is small, flexible, and extensible Smalltalk is an example of a programming environment Smalltalk introduces a new programming paradigm 69

70