Eric Roberts and Jerry Cain

Slides:



Advertisements
Similar presentations
JavaScript I. JavaScript is an object oriented programming language used to add interactivity to web pages. Different from Java, even though bears some.
Advertisements

IT253: Computer Organization Lecture 6: Assembly Language and MIPS: Programming Tonga Institute of Higher Education.
Program Design and Development
Introduction to a Programming Environment
Programming Logic and Design, Introductory, Fourth Edition1 Understanding Computer Components and Operations (continued) A program must be free of syntax.
Chapter 1 Program Design
Software design and development Marcus Hunt. Application and limits of procedural programming Procedural programming is a powerful language, typically.
Chapter 9 Interactive Multimedia Authoring with Flash - Introduction to Programming “Computers and Creativity” Richard D. Webster, COSC 109 Instructor.
Simple Program Design Third Edition A Step-by-Step Approach
CIS Computer Programming Logic
Created by, Author Name, School Name—State FLUENCY WITH INFORMATION TECNOLOGY Skills, Concepts, and Capabilities.
Serialization. Serialization is the process of converting an object into an intermediate format that can be stored (e.g. in a file or transmitted across.
Lecture 2: Logical Problems with Choices. Problem Solving Before writing a program Have a thorough understanding of the problem Carefully plan an approach.
Property of Jack Wilson, Cerritos College1 CIS Computer Programming Logic Programming Concepts Overview prepared by Jack Wilson Cerritos College.
CONTENTS Processing structures and commands Control structures – Sequence Sequence – Selection Selection – Iteration Iteration Naming conventions – File.
I Power Higher Computing Software Development High Level Language Constructs.
Data Structures and Algorithms Dr. Tehseen Zia Assistant Professor Dept. Computer Science and IT University of Sargodha Lecture 1.
Program Design. Simple Program Design, Fourth Edition Chapter 1 2 Objectives In this chapter you will be able to: Describe the steps in the program development.
Some of the utilities associated with the development of programs. These program development tools allow users to write and construct programs that the.
Data-Driven Programs Eric Roberts CS 106A February 26, 2016.
Bill Tucker Austin Community College COSC 1315
Multidimensional Arrays
Jerry Cain and Eric Roberts
Unit 2 Technology Systems
Advanced Computer Systems
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Chapter 10 Programming Fundamentals with JavaScript
Topics Designing a Program Input, Processing, and Output
IGCSE 4 Cambridge Data types and arrays Computer Science Section 2
CSC 221: Computer Programming I Spring 2010
Eric Roberts and Jerry Cain
CSC 221: Computer Programming I Fall 2005
CS 326 Programming Languages, Concepts and Implementation
Programming Mehdi Bukhari.
Functions in C++ Eric Roberts CS 106B January 7, 2015.
CS101 Introduction to Computing Lecture 19 Programming Languages
JSON Crash Course Traversy Media.
Data-Driven Programs Eric Roberts CS 106A February 26, 2010.
Scope, Objects, Strings, Numbers
JavaScript Syntax and Semantics
BY GAWARE S.R. COMPUTER SCI. DEPARTMENT
Programming Fundamentals
A290 TOOLS IN COMPUTING: JAVASCRIPT
Web Programming– UFCFB Lecture 17
CS 240 – Lecture 11 Pseudocode.
Assembler, Compiler, Interpreter
Chapter 10 Programming Fundamentals with JavaScript
Lecture 2: Logical Problems with Choices
Jerry Cain and Eric Roberts
WEB PROGRAMMING JavaScript.
Programming in JavaScript
Coding Concepts (Basics)
slides courtesy of Eric Roberts
Introduction C is a general-purpose, high-level language that was originally developed by Dennis M. Ritchie to develop the UNIX operating system at Bell.
Coding Concepts (Data- Types)
Multidimensional Arrays
Assembler, Compiler, Interpreter
Fundamentals of Python: First Programs
Programming in JavaScript
Programming in JavaScript
Programming in JavaScript
The Java switch Statement
C programming Language
Introduction to Data Structure
'Boolean' data type.
Topics Designing a Program Input, Processing, and Output
Topics Designing a Program Input, Processing, and Output
JavaScript CS 4640 Programming Languages for Web Applications
slides courtesy of Eric Roberts
Presentation transcript:

Eric Roberts and Jerry Cain Data-Driven Programs Eric Roberts and Jerry Cain CS 106J May 24, 2017

Once upon a time . . . 2

Computing and the Counterculture Two recent books argue that the personal computing revolution owes as much to the counterculture of the 1960s as it does to the technological strength and entrepreneurial spirit of Silicon Valley.

Ted Nelson’s Cyberspace Dreams The countercultural vision comes across particularly clearly in the two-sided book Computer Lib/Dream Machines which was written by cyberspace visionary Ted Nelson in 1974.

Data-Driven Programs 5

Designing Data Structures When you design a program, one of the first tasks you need to undertake is understanding how the underlying data structures fit together and how each level of the data hierarchy can best be represented. This process is similar to that of decomposing a large problem into a set of successively simpler subproblems. In the data domain, the information your program needs to process must be decomposed into successively simpler data structures until everything can be represented using a built-in JavaScript value, such as a number or a string. The tools for data decomposition you have seen so far include Arrays, which implement sequences of values Aggregates, which represent collections of related values Maps, which establish a relationship between keys and values

Exercise: Localization To be successful in our global economy, modern applications must support a wide variety of languages. The process of tailoring an application to communicate with users in the appropriate language is called localization. Suppose you want to be able to specify labels for buttons in English but would like to design a data structure that converts those names to the locale, represented as a two-character abbreviation, such as "fr" for France or "de" for Germany. Design a data structure that stores localized translations for any number of button labels in any number of localizations. The idea is that your data structure should allow clients to call localize(name, locale) with the English version of the button name and have it return the appropriate translation for the specified locale.

Data-Driven Programs In most programming languages, data structures are easier to manipulate than code. As a result, it is often useful to design applications so that as much of their behavior as possible is represented as data rather than in the form of methods. Programs that work this way are said to be data driven. In a data-driven system, the actual program (which is called a driver) is usually very small. Such driver programs operate in two phases: Read data from a file into a suitable internal data structure. 1. Use the data structure to control the flow of the program. 2. To illustrate the idea of a data-driven system, we’re going to spend most of this lecture building a programmed-instruction “teaching machine” of the sort that Ted Nelson discusses (mostly critically) in Dream Machines.

The Course Data File In our teaching machine application, the course designer—who is an expert in the domain of instruction and not necessarily a programmer—creates a data file that serves as the driver. The general format of the whole file is shown on the left, and a specific example of a question and its answers appears on the right.

Choosing an Internal Representation The first step in building the teaching machine is to design a set of classes that can represent the data and relationships in the file. All of the relevant data should be accessible from a single structure that contains all relevant information in a nested series of classes. course TMCourse TMQuestion array of strings questions title questionText answers map number  question map string  number

Converting External to Internal Form Java programming review 1 Would you like help with int or boolean type? ----- int: 2 boolean: 10 2 True or false: Integers can have fractional parts. true: 3 false: 5 3 No. Floating-point numbers have fractional parts; integers do not. be negative. true: 5 false: 4

Code for the TMQuestion Class /* * Creates a new question containing the text as an array of lines. * Clients must add new answer/question pairs by calling addAnswer. */ function TMQuestion(text) { var answerTable = { }; return { printQuestionText: function() { for (var i = 0; i < text.length; i++) { console.log(text[i]); } }, addAnswer: function(response, nextQuestion) { answerTable[response] = nextQuestion; lookupAnswer: function(response) { return answerTable[response]; };

Code for the TMCourse Class /* * File: TMCourse.java * ------------------- * This class defines the data structure for a course for use with * the TeachingMachine program. */ /* Constants */ const MARKER = "-----"; * Creates a new course for the teaching machine by reading the * data from the specified file, which consists of questions and * their accepted answers. function TMCourse(filename) { . }

Code for the TMCourse Class function TMCourse(filename) { var lines = File.readLines(filename); if (lines === undefined) return null; var nLines = lines.length; var title = lines.shift(); var questions = { }; var line = lines.shift(); while (line !== undefined) { var qnum = parseInt(line); var text = [ ]; while (line !== undefined && line !== MARKER) { text.push(line); line = lines.shift(); } var question = TMQuestion(text); while (line !== undefined && line !== "") { var colon = line.indexOf(":"); var response = line.substring(0, colon).toLowerCase().trim(); var nextQuestion = parseInt(line.substring(colon + 1).trim()); question.addAnswer(response, nextQuestion); questions[qnum] = question; return { getTitle: function() { return title; }, getQuestion: function(qnum) { return questions[qnum]; } }; /* * File: TMCourse.java * ------------------- * This class defines the data structure for a course for use with * the TeachingMachine program. */ /* Constants */ const MARKER = "-----"; * Creates a new course for the teaching machine by reading the * data from the specified file, which consists of questions and * their accepted answers. function TMCourse(filename) { . }

Code for TeachingMachine.js /* * File: TeachingMachine.js * ------------------------ * This program executes a programmed instruction course. */ import "TMCourse.js"; import "TMQuestion.js"; import "file"; function TeachingMachine() { var callback = function(filename) { var course = TMCourse(filename); if (course === null) { console.log("Can't read that file."); console.requestInput("Enter name of course file: ", callback); } else { stepThroughCourse(course); } };

Code for TeachingMachine.js /* * Steps through the course, asking questions and checking responses. */ function stepThroughCourse(course) { var qnum = 1; var askQuestion = function() { if (qnum === 0) { console.log("Done"); } else { var question = course.getQuestion(qnum); if (question === undefined) { console.log("Missing question " + qnum); question.printQuestionText(); console.requestInput(checkAnswer); } }; . /* * File: TeachingMachine.js * ------------------------ * This program executes a programmed instruction course. */ import "TMCourse.js"; import "TMQuestion.js"; import "file"; function TeachingMachine() { var callback = function(filename) { var course = TMCourse(filename); if (course === null) { console.log("Can't read that file."); console.requestInput("Enter name of course file: ", callback); } else { stepThroughCourse(course); } };

Code for TeachingMachine.js var checkAnswer = function(line) { var question = course.getQuestion(qnum); var nextQuestion = question.lookupAnswer(line); if (nextQuestion === undefined) { console.log("I don't understand that response."); } else { qnum = nextQuestion; } askQuestion(); }; console.log(course.getTitle()); /* * Steps through the course, asking questions and checking responses. */ function stepThroughCourse(course) { var qnum = 1; var askQuestion = function() { if (qnum === 0) { console.log("Done"); } else { var question = course.getQuestion(qnum); if (question === undefined) { console.log("Missing question " + qnum); question.printQuestionText(); console.requestInput(checkAnswer); } }; .

The End