Robo David Davenport Computer Eng. Dept., Bilkent University Ankara - Turkey. lightning introduction to the engineering.

Slides:



Advertisements
Similar presentations
Everyday Algorithms David Davenport Computer Eng. Dept., Bilkent University Ankara - Turkey. lightning introduction to.
Advertisements

Any questions on the Section 5. 8 homework
Computer Science 1000 LOGO I. LOGO a computer programming language, typically used for education an old language (1967) the basics are simple: move a.
Zero to Java in Internet Time David Davenport Computer Engineering Dept., Bilkent University, Ankara Turkey
How to Debug VB .NET Code.
Robo David Davenport Computer Eng. Dept., Bilkent University Ankara - Turkey. lightning introduction to the engineering.
Programming Fundamentals (750113) Ch1. Problem Solving
Robot? What’s a Robot? Introducing Karel-the-Robot.
Chapter 3 Planning Your Solution
By Jennifer Adams. The traditional approach (or algorithm) for large number division is the most abstract and difficult approach to division. Yet many.
What is Scratch? Scratch as Logo Dr. Ben Schafer Department of Computer Science University of Northern Iowa.
Activity 1 - WBs 5 mins Go online and spend a moment trying to find out the difference between: HIGH LEVEL programming languages and LOW LEVEL programming.
SOLIDWORKS: Lesson III – Patterns & Mirrors
SuperCorners. Problem The Corners sample robot has a simple strategy: first, move into a corner of the arena, and second sweep the gun back and forth.
EXAM TIPS What to do and What not to do!. ALWAYS SHOW YOUR WORKING OUT Most questions are worth two or more marks, so even if you make a slip and get.
Simplest Fractions for Whole Numbers. Look at this picture. How many parts are in each group? Yes, 4. What’s the bottom number for the fraction shown.
1 Shawlands Academy Higher Computing Software Development Unit.
Karel J Robot An introduction to BlueJ and Object- Oriented Programming.
Introduction This chapter gives you several methods which can be used to solve complicated equations to given levels of accuracy These are similar to.
TOPIC 3 INTRODUCTION TO PROGRAMMING 1 Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach by M. Guzdial and B.
Robo – Software Engineering David Davenport Computer Eng. Dept., Bilkent University Ankara - Turkey. engineering.
COMPSCI 101 Principles of Programming Lecture 28 – Docstrings & Doctests.
Program Development Life Cycle (PDLC)
1 The Software Development Process  Systems analysis  Systems design  Implementation  Testing  Documentation  Evaluation  Maintenance.
Documentation and Comments. What’s a comment? A comment is a simple form of documentation. Documentation is text that you the programmer write to explain.
Computer Programming TCP1224 Chapter 3 Completing the Problem-Solving Process and Getting Started with C++
Methods in Java CSC1401. Overview In this session, we are going to see how to create class-level methods in Java.
Georgia Institute of Technology Barb Ericson Georgia Institute of Technology May 2006 Teaching Java using Turtles part 2.
SE: CHAPTER 7 Writing The Program
Computational Algorithms David Davenport Computer Eng. Dept., Bilkent University Ankara - Turkey. lightning introduction.
Introduction to programming in the Java programming language.
C++ Basics C++ is a high-level, general purpose, object-oriented programming language.
Java Introduction part 2 CSC1401. Overview In this session, we are going to examine some of the instructions from the previous class in more detail.
CMSC 104, Version 8/061L17Top-DownDesign.ppt Top-Down Design Topics Top-Down Design Top-Down Design Examples The Function Concept Reading Sections 3.1.
The Software Development Process
Multiplying Mixed Numbers © Math As A Second Language All Rights Reserved next #7 Taking the Fear out of Math ×
1.7 Introduction to Perimeter, Circumference, and Area Geometry.
Top-down approach / Stepwise Refinement & Procedures & Functions.
Cartoon Similarity Using cartoons to draw similar figures
04/02/ Procedures Top-down approach / Stepwise Refinement & Sub Procedures.
1 The Software Development Process ► Systems analysis ► Systems design ► Implementation ► Testing ► Documentation ► Evaluation ► Maintenance.
Algorithms and Pseudocode
CMSC 2021 Software Development. CMSC 2022 Software Development Life Cycle Five phases: –Analysis –Design –Implementation –Testing –Maintenance.
BEGINNER FLL PROGRAMMING WORKSHOP BY DROIDS ROBOTICS & EV3LESSONS.
1 Taking Notes. 2 STOP! Have I checked all your Source cards yet? Do they have a yellow highlighter mark on them? If not, you need to finish your Source.
CMSC 104, Section 301, Fall Lecture 18, 11/11/02 Functions, Part 1 of 3 Topics Using Predefined Functions Programmer-Defined Functions Using Input.
Algorithms and Flowcharts
Basic Programming I Working with QBasic
ICS 3UI - Introduction to Computer Science
Math Class – Miss Purdue
Intro CS – Loops & Creating Shapes
Copyright © 2008 by Helene G. Kershner
This PowerPoint can be found on my Moodle page.
Copyright © 2008 by Helene G. Kershner
Robo – Software Engineering
Functions.
Programming Problem steps must be able to be fully & unambiguously described Problem types; Can be clearly described Cannot be clearly described (e.g.
Learning to program with Logo
Graph Paper Programming
Programming Fundamentals (750113) Ch1. Problem Solving
Programming Fundamentals (750113) Ch1. Problem Solving
An Introduction to VEX IQ Programming with Modkit
Theory of Computation Turing Machines.
Teaching Java using Turtles part 2
Introduction to TouchDevelop
Programming Fundamentals (750113) Ch1. Problem Solving
Tonga Institute of Higher Education IT 141: Information Systems
Programming Fundamentals (750113) Ch1. Problem Solving
Tonga Institute of Higher Education IT 141: Information Systems
Cartoon Similarity Using cartoons to draw similar figures
Presentation transcript:

Robo David Davenport Computer Eng. Dept., Bilkent University Ankara - Turkey. lightning introduction to the engineering of software

Robo Robo is a little robot with a pen you command him to move around he leaves a trail with the pen as he moves Robo’s world is infinite flat white surface Your objective: to have Robo produce given pattern/picture

Robo Commands f(x)- move forward x units r(x) - turn right x degrees l(x)- turn left x degrees p - pick up/put down the pen (switch drawing mode on/off) Initial condition middle of surface facing north in drawing mode One command at a time please! (i.e. only one per line) Sorry, but I can’t do any maths or even fractions!

Robo - examples Have Robo draw a straight line 100 units long a horizontal line 150 units long a 100 by 200 unit rectangle an equilateral triangle with 150 units sides a dashed line, 50 unit spaces, 100 unit dashes Points to note: Robo only understands f,r,l & p (not any natural language) Syntax error when Robo doesn’t understand command A program is a sequence of commands (instructions) Multiple correct solutions Simple isn’t it?

Robo - problem What is this? No one can IMMEDIATELY say what it is! How can we find out? TRACE it put yourself in position of Robo and follow the commands r(180) f(50) l(90) f(100) l(90) f(100) l(90) f(100) l(100) f(50) r(90) f(150) l(90) f(70) l(120) f(140) r(120) f(140) r(120) f(70)

Robo - solution After tracing... program has Logical Errors & needs to be corrected... DEBUG the program BUGS but it should look like this It looks like this!

Robo - TRACE & DEBUG Debug it... r(180) f(50) l(90) f(100) l(90) f(100) l(90) f(100) l(100) f(50) r(90) f(150) l(90) f(70) l(120) f(140) r(120) f(140) r(120) f(70) & check by tracing again! l(90)r(120) l(90) To correct... add, remove & change commands

Homework (Exercises)! Try one of these yourself StarComputer HouseRobot TreeCube Important your program should be correct i.e. it should be right-first-time Robo is asked to do (run/execute) it Design not experiment.

Reflections Your observations…? There must be an easier way to earn a living! How can we make our lives as programmers easier? Simple to follow Difficult to understand Long & therefore complex to do Difficult to debug and/or change Often use same/similar sets of commands Ok, now Robo programmers earn living by writing them but only if right-first-time! & jobs require HUGE pictures

The easy life... Ideas to make life easier comments blank space methods parameters repetition Top down structured design

Root cause of difficulties Lack of mapping btw problem & solution l(90) f(50) l(90) f(100) l(90) f(100) l(90) f(100) l(90) f(50) r(90) f(150) l(90) f(70) r(120) f(140) r(120) f(140) r(120) f(70) ? see some structure see no structure Program to draw a Wishing Well finally, draw roof then draw pole First draw base So add notes Problem: notes would cause syntax errors! Solution: modify Robo to ignore such notes.

Comments Are natural language notes written in the program Ignored by Robo (i.e. no syntax error) // any_natural_language_text syntax: // Wishing Well // Author: David // Date: Sept // draw base l(90) f(50) l(90) f(100) l(90) f(100) l(90) f(100) l(90) f(50) r(90) // draw pole f(150) l(90) // draw roof f(70) r(120) f(140) r(120) f(140) r(120) f(70) Use comments… to say what each section does, & to tell about the program as a whole Every program should have a Header, a block of comments at the top that detail what, where, when & by whom.

Comments Are natural language notes in program Ignored by Robo (i.e. no syntax error) Use for documentation purposes who, what, when, how, … // any_natural_language_text syntax: // Draw a house // Author: David // Date: Sept : // draw walls : example: : // draw left window : // draw door : Including information that explains how program works makes it easier to fix/change Tip: if changes are made, add comments to track who did what, when & why!

The Inheritance of the Labour Movement The British Labour Movement draws its inspiration from a history that goes back over many centuries. This movement arose directly from the twin struggles by the British people to control Parliament through the popular vote and to gain the right to organise free trade unions. The battle against the Combination Acts and similar legislation which made trade unionism illegal went hand in hand with the campaigns for working men and women to be represented in Parliament. But even before these historic struggles, which first saw the light of day in the industrial revolution, the origins of socialism can be traced back as far as the time of Christ himself and even to the Old Testament. Tony Benn, Aids to Reading Can you read this comfortably? theinheritanceofthelabourmovementthebritishlabourmovemen tdrawsitsinspirationfromahistorythatgoesbackovermanycentur iesthismovementarosedirectlyfromthetwinstrugglesbythebritis hpeopletocontrolparliamentthroughthepopularvoteandtogaint herighttoorganisefreetradeunionsthebattleagainstthecombinat ionactsandsimilarlegislationwhichmadetradeunionismillegalwe nthandinhandwiththecampaignsforworkingmenandwomentobe representedinparliamentbutevenbeforethesehistoricstruggles whichfirstsawthelightofdayintheindustrialrevolutiontheoriginso fsocialismcanbetracedbackasfarasthetimeofchristhimselfandev entotheoldtestamenttonybenn1979

Blank Space Help visualisation & reading Blank lines, indentation & spaces // Wishing Well // Author: David // Date: Sept // draw base l(90) f(50) l(90) f(100) l(90) f(100) l(90) f(100) l(90) f(50) r(90) // draw pole f(150) l(90) // draw roof f(70) r(120) f(140) r(120) f(140) r(120) f(70) First see 3 parts then comments then code Combine Comments & Blank space Answers without tracing! Aid debugging & maintenance What does this code do? // Wishing Well // Author: David // Date: Sept // draw base l(90) f(50) l(90) // left f(100) l(90) // bottom f(100) l(90) // right f(100) l(90) f(50) r(90) // draw pole f(150) l(90) // draw roof f( 70) r( 120) f( 140) r( 120) f( 140) r( 120) f( 70)

Methods Are named blocks of commands Short, so easier to understand Facilitates reuse, testing & debugging d method_name syntax: Defining method: // Draw … // Author: … // Date: … : // draw … : method_name Using method: Example: // Draw pole f(150) l(90) pole d pole

Wishing Well using methods // draw roof of wwell // Author: David // Date: Sept f(70) l(120) f(140) r(120) f(140) r(120) f(70) roof // draw base of wwell // Author: David // Date: Sept l(90) f(50) l(90) f(100) l(90) f(100) l(90) f(100) l(100) f(50) r(90) base // Wishing Well // Author: David // Date: Sept // draw base d base // draw pole f(150) l(90) // draw roof d roof wwell

& again…? Changed method names What does it do now? (remember comments are ignored) // draw roof of wwell // Author: David // Date: Sept f(70) r(120) f(140) r(120) f(140) r(120) f(70) a123 // draw base of wwell // Author: David // Date: Sept l(90) f(50) l(90) f(100) l(90) f(100) l(90) f(100) l(90) f(50) r(90) xyz // Wishing Well // Author: David // Date: Sept // draw base d xyz // draw pole f(150) l(90) // draw roof d a123 wwell …it looks like a wishing well, but… MORAL – use meaningful names! d xyz d pole d a123 wwell // draw pole of wwell // Author: David // Date: Sept f(150) l(90) pole

House 250 x 250 x x x x 100

House f(50) r(90) f(50) r(90) f(50) r(90) f(50) r(90) window f(250) r(90) f(250) r(90) f(250) r(90) f(250) r(90) walls f(150) r(90) f(50) r(90) f(150) r(90) f(50) r(90) door housebody d walls r(90) f(100) l(90) d door p f(125) l(90) f(75) r(90) p d window p r(90) f(150) l(90) p d window house d housebody p f(125) l(90) f(175) r(120) p d roof roof f(250) r(120) f(250) r(120) f(250)

Generalize methods Looking at specific method instances notice repetition of similar code so, abstract/generalize through parameters f(50) r(90) f(50) r(90) f(50) r(90) f(50) r(90) window f(250) r(90) f(250) r(90) f(250) r(90) f(250) r(90) walls f(150) r(90) f(50) r(90) f(150) r(90) f(50) r(90) door f( height) r(90) f( width) r(90) f( height) r(90) f( width) r(90) rect( width, height) These are known as formal parameters They must be replaced with actual values when the Robo does the method Can you write equtri?

Using general methods Example, in place of draw door: d door Need to say “draw rectangle with width=50 & height=150” Use notation d rect( 50, 150) f(150) r(90) f(50) r(90) f(150) r(90) f(50) r(90) door f( height) r(90) f( width) r(90) f( height) r(90) f( width) r(90) rect( width, height) Actual parameter values f( 150) r(90) f( 50) r(90) f( 150) r(90) f( 50) r(90) rect( 50, 150) Replace formal parameters with actual parameter values

Rewriting the house program Using general rectangle method in place of draw door: d door say “draw rectangle with width=50 & height=150” i.e. d rect( 50, 150) in place of draw walls: d walls say “draw rectangle with height=250 & width=250” i.e. d rect( 250, 250) d roof d walls d leftwindow d rightwindow d door house d roof d rect( 250, 250) d rect( 50, 50) d rect( 50, 150) house Now need comments!

Restricted parameter names! Robo allows only names: a, b, c, d translate rect method for Robo… f( height) r(90) f( width) r(90) f( height) r(90) f( width) r(90) rect( width, height) f( b) r(90) f( a) r(90) f( b) r(90) f( a) r(90) rect( a, b, c, d ) Robo methods always have these four formal parameters, even if they are not used. For this reason, they are not explicitly written each time. Now need to include comments to say what a, b, c & d represent… // Params: a – width, b - height

Methods are independent! Methods can call other methods only connection is parameter list matched one-by-one in order, not by name! d moveturn( b, 90) d moveturn( a, 90) d moveturn( b, 90) d moveturn( a, 90) rect( a, b) d rect( a, b) r( c) rectturn( a, b, c) f( a) r( b) moveturn( a, b) Must understand: a’s, b’s, etc. are different in each method.

Repetition Automatically repeat method x 2 halfrect( a, b) rect( a, b) x c rectturn( a, b, d) pretty( a, b, c, d) d moveturn( b, 90) d moveturn( a, 90) halfrect( a, b) d rect( a, b) r( c) rectturn( a, b, c) f( a) r( b) moveturn( a, b) x number_of_times method_name ( parameter_list ) syntax: x 10 rectturn( a, b, 36) pretty( a, b) Try doing square & rewriting equtri

Repetition -- HECTOGONAL EQUTRI // equilateral // triangle f(a) r(120) f(a) r(120) f(a) d equtri(a) r(180) r(30) x 6 sequtri(a) r(30) x 3 equtri(a) l(60) x 3 equtri(a) sequtri hecto1 hecto2

Repetition -- CİRCLE r(a) f(b) circlepart x 360 circlepart(1,1) circle

Summary You should have learnt about & understand the rationale for… Comments White space Meaningfully named methods Method parameters Repetition Coming next… Top-down structured design!