1 CS101 Introduction to Computing Lecture 44 Programming Methodology (Web Development Lecture 15)

Slides:



Advertisements
Similar presentations
Introducing JavaScript
Advertisements

1 CS101 Introduction to Computing Lecture 17 Algorithms II.
1 CS101 Introduction to Computing Lecture 41 Images & Animation (Web Development Lecture 14)
Chapter 3: Editing and Debugging SAS Programs. Some useful tips of using Program Editor Add line number: In the Command Box, type num, enter. Save SAS.
An Introduction to Java Programming and Object- Oriented Application Development Chapter 8 Exceptions and Assertions.
The Web Warrior Guide to Web Design Technologies
2440: 211 Interactive Web Programming JavaScript Fundamentals.
1 CS101 Introduction to Computing Lecture 23 Flow Control & Loops (Web Development Lecture 8)
Working with JavaScript. 2 Objectives Introducing JavaScript Inserting JavaScript into a Web Page File Writing Output to the Web Page Working with Variables.
Chapter 16 Dynamic HTML and Animation The Web Warrior Guide to Web Design Technologies.
1 Web Wizards Guide To PHP David Lash Chapter 1 Introduction to PHP.
Tutorial 10 Programming with JavaScript
XP 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial 10.
SUNY Morrisville-Norwich Campus-Week 12 CITA 130 Advanced Computer Applications II Spring 2005 Prof. Tom Smith.
XP Tutorial 1 New Perspectives on JavaScript, Comprehensive1 Introducing JavaScript Hiding Addresses from Spammers.
1 CS101 Introduction to Computing Lecture 29 Functions & Variable Scope (Web Development Lecture 10)
Programming Games Computer science big ideas. Computer Science jargon. Show virtual dog Homework: [Catch up: dice game, credit card or other form.] Plan.
JS Arrays, Functions, Events Week 5 INFM 603. Agenda Arrays Functions Event-Driven Programming.
Javascript and the Web Whys and Hows of Javascript.
JavaScript, Fifth Edition Chapter 1 Introduction to JavaScript.
UNIT 3 TEMPLATE AND EXCEPTION HANDLING. Introduction  Program errors are also referred to as program bugs.  A C program may have one or more of four.
4 HTML Basics Section 4.1 Format HTML tags Identify HTML guidelines Section 4.2 Organize Web site files and folder Use a text editor Use HTML tags and.
Amber Annett David Bell October 13 th, What will happen What is this business about personal web pages? Designated location of your own web page.
WEEK 3 AND 4 USING CLIENT-SIDE SCRIPTS TO ENHANCE WEB APPLICATIONS.
CNIT 133 Interactive Web Pags – JavaScript and AJAX JavaScript Environment.
Lesson 19. JavaScript errors Since JavaScript is an interpreted language, syntax errors will usually cause the script to fail. Both browsers will provide.
General Programming Introduction to Computing Science and Programming I.
CSS Class 7 Add JavaScript to your page Add event handlers Validate a form Open a new window Hide and show elements Swap images Debug JavaScript.
Section 4.1 Format HTML tags Identify HTML guidelines Section 4.2 Organize Web site files and folder Use a text editor Use HTML tags and attributes Create.
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
Client Scripting1 Internet Systems Design. Client Scripting2 n “A scripting language is a programming language that is used to manipulate, customize,
Introduction to HTML. What is a HTML File?  HTML stands for Hyper Text Markup Language  An HTML file is a text file containing small markup tags  The.
1 JavaScript in Context. Server-Side Programming.
XP Tutorial 10New Perspectives on Creating Web Pages with HTML, XHTML, and XML 1 Working with JavaScript Creating a Programmable Web Page for North Pole.
Tutorial 10 Programming with JavaScript. XP Objectives Learn the history of JavaScript Create a script element Understand basic JavaScript syntax Write.
CS105 INTRODUCTION TO COMPUTER CONCEPTS HTML Instructor: Cuong (Charlie) Pham.
XHTML By Trevor Adams. Topics Covered XHTML eXtensible HyperText Mark-up Language The beginning – HTML Web Standards Concept and syntax Elements (tags)
LEARNING HTML PowerPoint #1 Cyrus Saadat, Webmaster.
XP Tutorial 10New Perspectives on HTML and XHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial.
Introducing Python CS 4320, SPRING Lexical Structure Two aspects of Python syntax may be challenging to Java programmers Indenting ◦Indenting is.
ECA 225 Applied Interactive Programming1 ECA 225 Applied Online Programming basics.
Chapter 2: Variables, Functions, Objects, and Events JavaScript - Introductory.
4 HTML Basics Section 4.1 Format HTML tags Identify HTML guidelines Section 4.2 Organize Web site files and folder Use a text editor Use HTML tags and.
CS101: Introduction to Computer Science Slides adapted from Sedgewick and Wayne Copyright © Your First Java.
4. Javascript M. Udin Harun Al Rasyid, S.Kom, Ph.D Lab Jaringan Komputer (C-307) Desain.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
1 Server versus Client-Side Programming Server-SideClient-Side.
1 JavaScript in Context. Server-Side Programming.
HTML Basics. HTML Coding HTML Hypertext markup language The code used to create web pages.
Kevin Murphy Images and Web Pages Masters Project CS 490.
Objective You will be able to define the basic concepts of object-oriented programming with emphasis on objects and classes by taking notes, seeing examples,
JavaScript. JavaScript Introduction JavaScript is the world's most popular programming language. It is the language for HTML and the web, for servers,
CS116 COMPILER ERRORS George Koutsogiannakis 1. How to work with compiler Errors The Compiler provide error messages to help you debug your code. The.
Understanding JavaScript and Coding Essentials Lesson 8.
Tutorial 10 Programming with JavaScript. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Learn the history of JavaScript.
Introduction to Arrays. Learning Objectives By the end of this lecture, you should be able to: – Understand what an array is – Know how to create an array.
1 CSC160 Chapter 1: Introduction to JavaScript Chapter 2: Placing JavaScript in an HTML File.
Introduction to Javascript. What is javascript?  The most popular web scripting language in the world  Used to produce rich thin client web applications.
Javascript Basic Concepts Presentation By: Er. Sunny Chanday Lecturer CSE/IT RBIENT.
XP Tutorial 10New Perspectives on HTML, XHTML, and DHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties.
L071 Introduction to C Topics Compilation Using the gcc Compiler The Anatomy of a C Program Reading Sections
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
Programming Basics - RobotC Introduction to Robotics.
Java Programming Fifth Edition Chapter 1 Creating Your First Java Classes.
The Web Wizard’s Guide To JavaScript Chapter 4 Image Swapping.
During the last lecture we had a discussion on Data Types, Variables & Operators
The Web Wizard’s Guide To JavaScript
Lecture 8 Programming Paradigm & Languages. Programming Languages The process of telling the computer what to do Also known as coding.
Presentation transcript:

1 CS101 Introduction to Computing Lecture 44 Programming Methodology (Web Development Lecture 15)

2 During the last lecture we discussed Graphics & Animation We became able to add and manipulate images and simple animations to a Web page

3 Images in HTML It is quite straight forward to include gif and jpg images in an html Web page using the tag Format: <IMG src=URL, alt=text height=pixels width=pixels align="bottom|middle|top"> Plea: Don’t use images just for the sake of it!

4 Images in JavaScript Images in JavaScript can be manipulated in many ways using the built-in object, Image Properties: name, border, complete, height, width, hspace, vspace, lowsrc, src Methods: None Event handlers: onAbort, onError, onLoad, etc.

5 Image Preloading The primary use for an Image object is to download an image into the cache before it is actually needed for display This technique can be used to create smooth animations or to display one of several images based on the requirement

6 The Image Pre-Loading Process 1.An instance of the Image object is created using the new keyword 2.The src property of this instance is set equal to the filename of the image to be pre-loaded 3.That step starts the down-loading of the image into the cache without actually displaying it 4.When a pre-loaded image is required to be displayed, the src property of the displayed image is set to the src property of the pre- fetched image

7 Animated Gifs We could have saved the 16 gif images of the previous example in a single file in the form of an animated gif, and then used it in a regular tag to display a moving image However, JavaScript provides better control over the sequencing and the gap between the individual images Example

8 Today’s Goals (Programming Methodology) To understand effective programming practices that result in the development of correct programs with minimum effort To become familiar with testing & debugging

9 programming methodology? The process used by an individual or a team for developing programs

10 programming methodology? good A methodology that enables the lowest-cost and on- schedule development of programs that are correct, easy to maintain & enhance

11 correct program? A program with correct syntax & semantics

12 readable program? A program that is easy to read & understand, and therefore, easy to maintain & enhance

13 swapFlag = true ; while ( swapFlag == true ) { swapFlag = false ; for ( k = 0 ; k < ht.length - 1 ; k++ ) { if ( ht[ k ] < ht[ k + 1 ] ) { temp = ht[ k + 1 ] ; ht[ k + 1 ] = ht[ k ] ; ht[ k ] = temp ; swapFlag = true ; } How can we make it more readable? What is its most complex aspect? Bubble Sort

14 for ( j = 0 ; j < ; j++ ) { for ( k = 0 ; k < ht.length - 1 ; k++ ) { if ( ht[ k ] < ht[ k + 1 ] ) { temp = ht[ k + 1 ] ; ht[ k + 1 ] = ht[ k ] ; ht[ k ] = temp ; }

15 Readable programs are: - more readable - efficient enough

16 guidelines

17 Design Guidelines Break your code down into short and simple functions (e.g. take the 3 swap statements out from the last example and put them into a function of their own) Do not use global variables

18 Coding Guidelines Always use semicolons to end statements Indent blocks of code (2 to 5 spaces) Identifiers: –Use the camelBack scheme –Make them descriptive but concise –Variables: nouns –Functions: verbs Comment liberally

19 Comments let the code speak for itself !

20 Guidelines for Developing Short Programs 1.Read, understand the problem 2.Do you have all the required data? No: Get it Else assume it. State it explicitly

21 Example: Problem Statement Develop a Web page that displays an order taking form It takes the number of items required for each product, multiplies with the prices, sums them up, adds the GST, and displays the total value of the order

22 Guidelines for Developing Short Programs 1.Read, understand the problem 2.Do you have all the required data? No: Get it Else assume it. State it explicitly 3.Do the design

23

24 Developing Short Programs 1.Read, understand the problem 2.Do you have all the required data? No: Get it Else assume it. State it explicitly 3.Do the design 4.Write test cases

25

26 Developing Short Programs 1.Read, understand the problem 2.Do you have all the required data? No: Get it Else assume it. State it explicitly 3.Do the design 4.Write test cases 5.Write the code on a piece of paper 6.Hand-check it 7.Type it in 8.Run & check it on test cases 9.Errors? fix & redo 9 Done!

27 Design & Code Reviews Probably the most efficient way of improving the a program Being humans, at time we see what is supposed to be there instead of what is actually there Another pair of eyeballs may not have the same problem, especially if they were not involved in building the design or code

28 Two Popular Review Methods 1.Give the problem statement, design, and code (that includes all assumptions) to a peer, and ask him/her to see if things have been done properly 2.Walk a peer or a group of peers through the problem, the design, and the code yourself Which of the two is better?

29 Is it possible to write defect- free programs ?

30 Is it even advisable to attempt writing programs that are free of defects ?

31 Testing & Debugging Testing: The tasks performed to determine the existence of defects Debugging: The tasks performed to detect the exact location of defects Defects are also called bugs or errors Let us now look at one of their classifications

32 Types of Errors Syntax errors Semantic errors Run-time errors

Syntax Errors They are caused by the code that somehow violates the rules of the language Easy to detect and fix errors The browser stops code interpretation on detecting one of these Examples: –a = b + * c ; –receiver = reciever + 2 Syntax error?

34 Semantic Errors Occur when a statement executes and has an effect not intended by the programmer Hard to detect during normal testing Often times occur only in unusual & infrequent circumstances The ‘+’ operator often results in unintended consequences. Remedy: Convert, before use

35 Run-Time Errors Occur when the program is running and tries to do something that is against the rules Example: Accessing a non-existent variable, property, method, object, etc (e.g. a method name is misspelled) Sources of these can be determined by a careful reading of the code, but unfortunately, not always!

36 Debugging

37 Tools : Internet Options… : Advanced :

38 name = "Bhola ; Syntax Error

39 checkPulse( ) ; Run-time Error

40 x = 1.3 ; x.upperCase( ) ; Run-time Error

41 income =document.myForm.salary.value + document.myForm.bonus.value ; Semantic Error

42

43 if ( today = “holiday” ) mood = “good” ;

44 if ( today == “holiday” ) ; mood = “good” ;

45 if ( today == “holiday” || weather == “OK” mood = “excellent” ;

46 function doThis ( tiger ) { box[ 0 ] = tiger ; x = box[ 0 ] ; return x ;

47 box = new array( 10 ) ;

48 box = new Array( 10 ) ; box( 0 ) = 43 ;

49 Helpful Editors Using smart editors (e.g. DreamWeaver, nedit) can help in avoiding many types of syntax errors They can, for example: –Automatically color different parts of statements in different colors, e.g. comments in Gray, strings in Green, HTML tags in Blue –Auto indent –Visually indicate the presence of mismatched parentheses, curly braces or square brackets

50 During Today’s Lecture … We looked at a few effective programming practices that result in the development of correct programs with minimum effort We also became familiar with testing & debugging

51 Final Lecture: Review & Wrap-Up To review a selection from the interesting ideas that we explored over the last 44 lectures