Download presentation source

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Join-pattern wikipedia , lookup

Smalltalk wikipedia , lookup

Smart Pascal wikipedia , lookup

Design Patterns wikipedia , lookup

Class (computer programming) wikipedia , lookup

Functional programming wikipedia , lookup

Name mangling wikipedia , lookup

Scala (programming language) wikipedia , lookup

Object-relational impedance mismatch wikipedia , lookup

Programming language wikipedia , lookup

Go (programming language) wikipedia , lookup

Abstraction (computer science) wikipedia , lookup

C++ wikipedia , lookup

Falcon (programming language) wikipedia , lookup

Control flow wikipedia , lookup

Interpreter (computing) wikipedia , lookup

C Sharp syntax wikipedia , lookup

Reactive programming wikipedia , lookup

JavaScript wikipedia , lookup

Java (programming language) wikipedia , lookup

Structured programming wikipedia , lookup

Java performance wikipedia , lookup

Object-oriented programming wikipedia , lookup

C Sharp (programming language) wikipedia , lookup

Transcript
Programming
Session 6
LBSC 690
Information Technology
Agenda
•
•
•
•
•
•
Questions
The mythical person-month
History of programming
Object oriented programming
Programming for the Web
JavaScript example
Software
• Software models aspects of reality
– Input and output represent the state of the world
– Software describes how the two are related
• Examples
– Ballistic computations
– Alta Vista
– Microsoft Word
Programming Languages
• Used to specify every detail of the model
• Special purpose
– Able to specify an entire class of models
• Spreadsheets (Excell, Quatro Pro, ...)
• Databases (Access, Paradox, Oracle, ...)
• General purpose
– Able to specify any possible model
• Pascal, C, Java, JavaScript, Perl, ...
The Mythical Person-Month
• If it would take one person three months,
why does it take four people SIX months?
–
–
–
–
The original estimate might have been too low
Partitioning strategy led to a long “critical path”
Training new people takes each some time
More people means more communications
Training Time
• Simple Example
–
–
–
–
Full time person = 2,000 hours/year
Part time person = 288 hours per year
No training  7 part time people
With training  10 part time people
• Learning the specification takes time
– Learning organizational “rules” takes longer!
Communications
• Sort of like continuous training
– Who needs to know what I just learned?
• Can be minimized by good partitioning
– Limit the number of interfaces
• Can be facilitated by computers
– Asynchronous communication techniques
• Email, private newsgroups, voice mail
Estimating Completion Time
• Rules of thumb
– 1/3 specification
– 1/6 coding
– 1/2 test planning, testing, and fixing!
• Add time for coding to learn as you go, but
don’t take time away from the other parts!
– Reread the section on “gutless estimating” if
you are tempted
History of Programming
• Machine code
– Zeroes and Ones
• Assembly language
– “Assembler” changes names to machine code
• High-level languages
– “Compiler” translates math to machine code
• Independent of machine “architecture”
– FORTRAN, COBOL
History of Programming
• Structured Programming
– Group instructions into meaningful abstractions
– C, Pascal, Perl
• Object oriented programming
– Group “data” and “methods” into “objects”
– Naturally represents responses to events
– C++, Java, JavaScript
Object Models
• Represent things in the world as “objects”
– Simplest objects are “variables”
• Represented with a name (n, teacher, …)
• May be assigned a value (n=4, teacher=“Doug”, …)
• Represent actions with “methods”
– Simplest methods are “operations”
• Represented with a symbol (+, -, *, /, …)
• “Classes” group objects with methods
– Classes model how kinds of things behave
• Objects are instances of classes
A Simple Example
• Variables:
• Operations:
Height, Weight, Shoe size
Multiply, Divide
• Method:
Shoe size=4*Weight/Height
• Class:
• Object:
Person
George
Statements
• Simple assignment statements
Birds = Hawks + Orioles
• Statements that invoke a method
document.write(“Hello World!”)
• Return a value from a method
return Birds
Combining Statements
to Make Methods
• Sequential
{… ; …; …; …}
• Conditional
if (i= =3) then {…} else {…}
try {…} catch (exception e) {…}
• Loop
for (i=0;i<10;i++) {…}
do {…} while (i<5)
Events
• Models an external stimulus
– program initiation, mouse click, mouseover, …
• Events result in the activation of a method
– Methods register the events to which they respond
• Conceptually, methods can run in parallel
– In practice, computers do one thing at a time
Arrays
• A set of elements
– For example, the number of days in each month
• Each element is assigned an index
– A number used to refer to that element
• For example, x[4] is the fifth element - count from zero
– Arrays and loops work naturally togther
Programming for the Web
• Common Gateway Interface (CGI) [Server side]
– Forms encode field values into a URL
– CGI passes field values to a Perl program
– Program generates a web page as a response
• JavaScript [Client-side, interpreted]
– Human-readable “source code” sent to the browser
– Web browser runs the program
• Java applets [Client-side, compiled]
– Machine-readable “bytecode” sent to browser
– Web browser runs the program
Your First JavaScript Program
• Launch a web browser
– Internet Explorer would be the best choice
•
•
•
•
•
http://glue.umd.edu/~oard/690/select.html
See how it behaves if you are 13 (or 65)
View source and read the program
Copy it to your ../pub directory on WAM
Make some changes and see how it works
Why Java?
• Java applets transfer and run faster
– “Bytecode” is more compact and easier to run
• Java applets can send and receive data
– A security policy limits what can be sent, though
• In Java you can create new classes
– This is helpful when writing complex programs
• Java strictly enforces data types
– This prevents some common kinds of mistakes
• You can stretch a statement over several lines
– Put a “;” at the end of each Java statement
Java Bytecode
• “Machine language” depends on the machine
– Programs compiled for a Sun won’t work on a PC
• Java claims “write once, run anywhere”
– Without recompiling
• JavaScript interpreters are slow
– Because they must read every character every time
• Java compiles to a standardized bytecode
– Which is organized like most machine languages
The Key Ideas
• Programming languages can model any problem
– Completely specifies output the for any input
• Object orientation matches human thought well
– Objects and actions are paired
– Simple control structures facilitate abstraction
• Events, sequential execution, conditional, iteration
• Language choice depends on the task
– For the Web: CGI (Perl), JavaScript, Java