Docsity

Programming Methodology - Introduction to Computing - Lecture Slides, Slides of Introduction to Computing

Partial preview of the text

Download Programming Methodology - Introduction to Computing - Lecture Slides and more Slides Introduction to Computing in PDF only on Docsity!

CS101 Introduction to Computing

Lecture 44

Programming Methodology

(Web Development Lecture 15)

During the last lecture we discussed Graphics & Animation

  • We became able to add and manipulate images and simple animations to a Web page

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.

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

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

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

programming

methodology?

10

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

correct

program?

11

A program with correct syntax & semantics

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 < 100000 ; 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 ;

} Docsity.com

guidelines

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

Comments let the

code speak for

itself!

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