Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Exercise Session 2.

Slides:



Advertisements
Similar presentations
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Exercise Session 5.
Advertisements

Chair of Software Engineering Concurrent Object-Oriented Programming Prof. Dr. Bertrand Meyer Exercise Session 1: Eiffel Introduction.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Lecture 7: References and Assignment.
Tutorial 8: Developing an Excel Application
The Web Warrior Guide to Web Design Technologies
Georgia Institute of Technology DrJava Appendix A Barb Ericson Georgia Institute of Technology May 2006.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Lecture 2: Dealing with Objects I.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Lecture 2: Dealing with Objects I.
Chair of Software Engineering 1 Introduction to Programming Bertrand Meyer Exercise Session 2 23 September 2008.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Lecture 6: Object Creation.
Chair of Software Engineering 1 Introduction to Programming Bertrand Meyer Exercise Session 3 29 September 2008.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Exercise Session 3.
Chair of Software Engineering 1 Introduction to Programming Bertrand Meyer Exercise Session 1 22 September 2009.
The IDE (Integrated Development Environment) provides a DEBUGGER for locating and correcting errors in program logic (logic errors not syntax errors) The.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Lecture 4: The Interface of a Class.
20-Jun-15 Eclipse. Most slides from: 2 About IDEs An IDE is an Integrated Development Environment.
1 Chapter 4 The Fundamentals of VBA, Macros, and Command Bars.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Lecture 4: The Interface of a Class.
Chair of Software Engineering OOSC - Summer Semester Object-Oriented Software Construction Bertrand Meyer.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Lecture 9: Abstraction.
Chair of Software Engineering OOSC - Summer Semester Object-Oriented Software Construction Bertrand Meyer Lecture 5: Project and EiffelStudio Presentation.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Exercise Session 7.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Exercise Session 2.
SUNY Morrisville-Norwich Campus-Week 12 CITA 130 Advanced Computer Applications II Spring 2005 Prof. Tom Smith.
Chair of Software Engineering OOSC - Summer Semester Object-Oriented Software Construction Bertrand Meyer Lecture 14: Presentation of EiffelStudio.
Chair of Software Engineering ATOT - Lecture 2, 2 April Advanced Topics in Object Technology Bertrand Meyer.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Lecture 6: Object Creation.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Exercise Session 2.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
Chapter 2: The Visual Studio.NET Development Environment Visual Basic.NET Programming: From Problem Analysis to Program Design.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Exercise Session 5.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Lecture 9: Abstraction.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Exercise Session 3.
DEBUGGERS For CS302 Data Structures Course Slides prepared by TALHA OZ (most of the text is from
1 Chapter One A First Program Using C#. 2 Objectives Learn about programming tasks Learn object-oriented programming concepts Learn about the C# programming.
Introducing Java.
Chapter 1 Introduction.
A First Program Using C#
Debugging applications, using properties Jim Warren – COMPSCI 280 S Enterprise Software Development.
Technology in Action Chapter 10 Behind the Scenes: Software Programming Copyright © 2014 Pearson Education, Inc. Publishing as Prentice Hall.
Tutorial 11 Using and Writing Visual Basic for Applications Code
Java Language and SW Dev’t
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Exercise Session 2.
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.
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
XP 1 Microsoft Word 2002 Tutorial 1 – Creating a Document.
CPSC1301 Computer Science 1 Overview of Dr. Java.
Classes CS 21a: Introduction to Computing I First Semester,
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Exercise Session 5.
Programming Fundamentals. Today’s Lecture Why do we need Object Oriented Language C++ and C Basics of a typical C++ Environment Basic Program Construction.
Chair of Software Engineering 1 Introduction to Programming Bertrand Meyer Exercise Session October 2008.
Chair of Software Engineering 1 Introduction to Programming Bertrand Meyer Exercise Session October 2008.
1 Lesson 18 Managing and Reporting Database Information Computer Literacy BASICS: A Comprehensive Guide to IC 3, 3 rd Edition Morrison / Wells.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Exercise Session 3.
Chair of Software Engineering 1 Introduction to Programming Bertrand Meyer Exercise Session October 2008.
15 Copyright © 2004, Oracle. All rights reserved. Debugging Triggers.
Eclipse 27-Apr-17.
1 Types of Programming Language (1) Three types of programming languages 1.Machine languages Strings of numbers giving machine specific instructions Example:
Chapter 3 Implementing Classes
Chapter 2 Build Your First Project A Step-by-Step Approach 2 Exploring Microsoft Visual Basic 6.0 Copyright © 1999 Prentice-Hall, Inc. By Carlotta Eaton.
Appendix A Barb Ericson Georgia Institute of Technology May 2006
Chapter 2: The Visual Studio .NET Development Environment
Appendix A Barb Ericson Georgia Institute of Technology May 2006
Using Visual Studio with C#
Eclipse 20-Sep-18.
Einführung in die Programmierung Introduction to Programming Prof. Dr
Einführung in die Programmierung Introduction to Programming Prof. Dr
Java IDE Dwight Deugo Nesa Matic Portions of the notes for this lecture include excerpts from.
Classes CS 21a: Introduction to Computing I
Workshop for Programming And Systems Management Teachers
Presentation transcript:

Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Exercise Session 2

2 Organizational  Assignments  One assignment per week  Will be put online Friday (before 17:00)  Should be handed in within eleven days (Tuesday, before 23:59)  Testat  You have to hand in n - 1 out of n assignments Must include the last one Show serious effort  You have to hand in two mock exams  Military service or illness -> contact assistant  Group mailing list  Is everybody subscribed?

3 Today  Give you the intuition behind object-oriented (OO) programming  Teach you about formatting your code  Distinguishing between  feature declaration and feature call  commands and queries  Understanding feature call chains  Getting to know the basics of EiffelStudio

4 Classes and objects  The main concept in Object-Oriented programming is the concept of Class.  Classes are pieces of software code meant to model concepts, e.g. “student”, “course”, “university”.  Several classes make up a program in source code form.  Objects are particular occurrences (“instances”) of concepts (classes), e.g. “student Reto” or “student Lisa”.  A class STUDENT may have many instances.

5 Classes and objects (again)  Classes are like templates (or molds) defining status and operations applicable to their instances.  A sample class STUDENT can define:  A student’s status: id, name and birthday  Operations applicable to all students: subscribe to a course, register for an exam.  Each instance (object) of class STUDENT will store a student’s name, id and birthday and will be able to execute operations such that subscribe to a course and register for an exam.  Only operations defined in a class can be applied to its instances.

6 Features  Feature declaration vs. feature call  You declare a feature when you write it into a class. set_name (a_name: STRING) -- Set `name’ to `a_name’. do name := a_name end  You call a feature when you apply it to an object. The object is called the target of this feature call. a_person.set_name (“Peter”)  Arguments, if any, need to be provided in feature calls. computer.shut_down computer.shut_down_after (3) ‏ telephone.ring_several (10, Loud) ‏  A feature is an operation that may be applied to certain classes of objects.

7 Features: Exercise  Class BANK_ACCOUNT defines the following operations:  deposit (a_num: INTEGER)  withdraw (a_num: INTEGER)  close  If b: BANK_ACCOUNT (b is an instance of class BANK_ACCOUNT) which of the following feature calls are possible?  b.deposit (10)  b.deposit  b.close  b.close (“Now”)  b.open  b.withdraw (100.50)  b.withdraw (0) Hands-On

8 Feature declaration Class name Comment Feature body Instructions Feature names Class text class PREVIEW feature explore -- Explore Zurich. do central_view  highlight zurich_map  animate end

9 Style rules Class names are upper-case Use tabs, not spaces, to highlight the structure of the program: it is called indentation. For feature names, use full words, not abbreviations. Always choose identifiers that clearly identify the intended role Use words from natural language (preferably English) for the names you define For multi-word identifiers, use underscores class PREVIEW feature explore -- Explore Zurich. do central_view.highlight zurich_map.animate end Tabs

10 Another example class BANK_ACCOUNT feature deposit (a_sum: INTEGER) -- Add `a_sum' to the account. do balance := balance + a_sum end balance: INTEGER end Within comments, use ` and ‘ to quote names of arguments and features. This is because they will be taken into account by the automatic refactoring tools.

11 Kinds of features: commands and queries  Commands  Modify the state of objects  Do not have a return value  May or may not have arguments  Examples: register a student to a course, assign an id to a student, record the grade a student got in an exam  … other examples?  Queries  Do not modify the state of objects  Do have a return value  May or may not have arguments  Examples: what is the age of a student? What is the id of a student? Is a student registered for a particular course?  … other examples?

12 Exercise: query or command?  What is the balance of a bank account?  Withdraw 400 CHF from a bank account  Who is the owner of a bank account?  Who are the clients of a bank whose total deposits are over 100,000 CHF?  Change the account type of a client  How much money can a client withdraw at a time?  Set a minimum limit for the balance of accounts  Deposit 300 CHF into a bank account Hands-On

13 Command-query separation principle “Asking a question shouldn’t change the answer” i.e. a query

14 Query or command? class DEMO feature procedure_name (a1: T1; a2, a3: T2) -- Comment do … end function_name (a1: T1; a2, a3: T2): T3 -- Comment do Result := … end attribute_name: T3 -- Comment end  no result  body  result  body  result  no body command query Predefined variable denoting the result

15 Feature Feature Features: the full story Command Query Feature Function No result Memory Computation Client view (specification) Internal view (implementation) Returns result Attribute Procedure Memory Computation Routine Feature

16 General form of feature call instructions Object1.query1.command (object2.query2, object3) targets arguments  Where are query1, query2 defined?  Where is command defined? Hands-On  Targets and arguments can be query calls themselves.

17 Qualified vs. unqualified feature calls  A qualified feature call has an explicit target.  An unqualified feature call is one whose target is the current object. The target is left out for convenience.  The current object of a feature is the object on which the feature is called. (what‘s the other name for this object?) assign_same_name (a_name: STRING; a_other_person: PERSON) -- Set `a_name’ to current person and `a_other_person’. do a_other_person.set_name(a_name) set_name (a_name) end person1.assign_same_name(“Hans”, person2) Qualified call Unqualified call, same as Current.set_name (a_name) assign_same_nameset_name call caller callee

18 EiffelStudio  EiffelStudio is a software tool (IDE) to develop Eiffel programs.  Help & Resources  Online guided tour: in EiffelStudio help menu      international.org/publications/files/ECMA- ST/ECMA-367.pdf international.org/publications/files/ECMA- ST/ECMA-367.pdf Integrated Development Environment

19 Components  editor  context tool  clusters pane  features pane  compiler  project settings ...

20 Editor  Syntax highlighting  Syntax completion  Auto-completion (CTRL+Space)  Class name completion (CTRL+SHIFT+Space)  Smart indenting  Block indenting or unindenting (TAB and SHIFT+TAB)  Block commenting or uncommenting (CTRL+K and SHIFT+CTRL+K)  Infinite level of Undo/Redo (reset after a save)  Quick search features (first CTRL+F to enter words then F3 and SHIFT+F3)  Pretty printing (CTRL+SHIFT+P)

21 Compiler highlights  Melting: uses quick incremental recompilation to generate bytecode for the changed parts of the system. Used during development (corresponds to the button “Compile”).  Freezing: uses incremental recompilation to generate more efficient C code for the changed parts of the system. Initially the system is frozen (corresponds to “Freeze…”).  Finalizing: recompiles the entire system generating highly optimized code. Finalization performs extensive time and space optimizations (corresponds to “Finalize…”)

22 Debugger: setup  The system must be melted/frozen (finalized systems cannot be debugged).  Setting and unsetting breakpoints  An efficient way consists in dropping a feature in the context tool.  Alternatively, you can select the flat view  Then click on one of the little circles in the left margin to enable/disable single breakpoints.  Use the toolbar debug buttons to enable or disable all breakpoints globally.

23 Debugger: run  Run the program by clicking on the Run button.  Pause by clicking on the Pause button or wait for a triggered breakpoint.  Analyze the program:  Use the call stack pane to browse through the call stack.  Use the object tool to inspect the current object, the locals and arguments.  Run the program or step over (or into) the next statement, or out of the current one.  Stop the running program by clicking on the Stop button.