22
Programming Languages CPS120: Introduction to Computer Science Lecture 5

Programming Languages CPS120: Introduction to Computer Science Lecture 5

Embed Size (px)

Citation preview

Page 1: Programming Languages CPS120: Introduction to Computer Science Lecture 5

Programming LanguagesProgramming Languages

CPS120: Introduction to Computer ScienceLecture 5

Page 2: Programming Languages CPS120: Introduction to Computer Science Lecture 5

Programming LanguagesProgramming Languages

A programming language is a set of rules that provides a way of telling a computer what operations to perform.

Page 3: Programming Languages CPS120: Introduction to Computer Science Lecture 5

Levels of Programming LanguagesLevels of Programming Languages

Machine language Assembly Language High Level Languages Fourth Generation Languages (4GL)

Page 4: Programming Languages CPS120: Introduction to Computer Science Lecture 5

Machine Languages

different for each computer processor

0100001101 100000 001101 11000100101 10001 1000001110111001. . .

Page 5: Programming Languages CPS120: Introduction to Computer Science Lecture 5

Assembly Languages

different for each computer processor

main proc paymov ax, dsegmov ax, 0b00hadd ax, dxmov a1, b1mul b1, axmov b1, 04h

Page 6: Programming Languages CPS120: Introduction to Computer Science Lecture 5

High-Level LanguagesHigh-Level Languages

Higher Level LanguagesUse traditional programming logic where the programming instructions tell the computer what to do and how to perform the required operations.

4GLsUse high-level English-like instructions to specify what to do, not how to do it .

Page 7: Programming Languages CPS120: Introduction to Computer Science Lecture 5

Interpreter vs. CompilerInterpreter vs. Compiler

InterpreterTranslates instructions to machine code line-by-line.

CompilerTranslates the entire program to machine code before running it.

Page 8: Programming Languages CPS120: Introduction to Computer Science Lecture 5

Types of Programming LanguagesTypes of Programming Languages

Machine language Procedure-oriented languages Object-oriented languages Event-driven languages

Page 9: Programming Languages CPS120: Introduction to Computer Science Lecture 5

Early Language HistoryEarly Language History FORTRAN (short for Formula Translator, developed in the 1950s by IBM In 1958, a language called ALGOL (Algorithm Language) was developed COBOL (Common Business Oriented Language) was created in 1960 to serve

as the primary language for large-scale programs In 1964, the BASIC language (Beginners All-Purpose Symbolic Instruction

Code) was first used In 1965, a language called PL/I was developed in hopes of being everything to

everyone. PL/I proved to be too complex. In the late 1960s, Niklaus Wirth developed a teaching language called Pascal.

Page 10: Programming Languages CPS120: Introduction to Computer Science Lecture 5

Later Language HistoryLater Language History Ada, which was developed in 1983, is large and complex. Smalltalk is graphical and object-oriented. Concepts developed

with Smalltalk were important to the development and continued development of languages like C++ and Java

The C language was derived from ALGOL. C++ is C with the addition of object-oriented concepts.

Page 11: Programming Languages CPS120: Introduction to Computer Science Lecture 5

Procedure-Oriented LanguagesProcedure-Oriented Languages

FORTRAN COBOL Pascal C Ada

Page 12: Programming Languages CPS120: Introduction to Computer Science Lecture 5

OOED LanguagesOOED Languages

Object-oriented languagesSmalltalkC++Ada 95

Event-driven languagesVisual Basicmost Visual languages

Page 13: Programming Languages CPS120: Introduction to Computer Science Lecture 5

What Can a Program Do?

A program can only instruct a computer to:Read InputSequenceCalculateStore dataCompare and branchIterate or LoopWrite Output

Page 14: Programming Languages CPS120: Introduction to Computer Science Lecture 5

Fundamental Programming ConceptsFundamental Programming Concepts

Assignment of values to a variable Iteration (Looping)

Over a set of set of statementsWith respect to a logical expressions (conditions)

Delegation of sub-tasks to functions / procedures

Page 15: Programming Languages CPS120: Introduction to Computer Science Lecture 5

The Structure TheoremThe Structure Theorem

The Structure Theorem states that any algorithm can be built from three basic control structures.

One-after-another (Sequence) Decision-making (Selection)

Making choices between 2 or more alternatives Repetition (Iteration)

Concerned with repetitive tasks (and the termination conditions of loops)

Page 16: Programming Languages CPS120: Introduction to Computer Science Lecture 5

C++ Control StructuresC++ Control Structures

1. "Sequence statements" are imperatives2. "Selection" is the "if then else" statement

– AND, OR, NOT and parentheses ( ) can be used for compound conditions

3. "Iteration" is satisfied by a number of statements– "while" – " do " – "for"

4. The case-type statement is satisfied by the "switch" statement.

– CASE statements are used for most non-trivial selection decisions

Page 17: Programming Languages CPS120: Introduction to Computer Science Lecture 5

Programmer Productivity ToolsProgrammer Productivity Tools

Modular Programming Structured Programming Object-oriented Programming

Page 18: Programming Languages CPS120: Introduction to Computer Science Lecture 5

Modular ProgrammingModular Programming

Large programs are divided by functional parts into subroutines

Strong cohesionLoose coupling

Page 19: Programming Languages CPS120: Introduction to Computer Science Lecture 5

Structured Programming

Composed of sequence, decision (selection), and repetition (looping or iteration) structures

Structured program languages lend themselves to flowcharts, structure charts, and pseudocode.

Structured programming languages work best where the instructions have been broken up into small, manageable parts.

Looks at a problem as proceduresData are maintained separately from data

Page 20: Programming Languages CPS120: Introduction to Computer Science Lecture 5

Structured Program RulesStructured Program Rules

1. Use only sequence, decision, and repetition2. Only one entrance into and one exit from a structure3. Connectors only allowed when continuing processing

from one column or page to another4. Decision and repetition structures can be nested5. Only one STOP instruction is permitted. It must be in

the MAINLINE routine

Page 21: Programming Languages CPS120: Introduction to Computer Science Lecture 5

Structured Programming AdvantagesStructured Programming Advantages

Standard method for solving problems GO-TO less Easier to test and debug Written by more than one programmer Reusability Thrashing minimized

Page 22: Programming Languages CPS120: Introduction to Computer Science Lecture 5

Object-Oriented ProgramsObject-Oriented Programs Developed to respond to programming issues that

structured programming did not adequately address1. Rarely possible to anticipate the design of a completed

system before implementation2. GUIs were difficult to develop in traditional procedure-

oriented languages3. Sharing data across routines is error prone

Information hiding allows programmers to determine what data is exposed to various routines