McGraw-Hill The McGraw-Hill Companies, Inc.,

41  Download (0)

Full text

(1)
(2)

Objectives:

To describe the evolution of programming languages from machine language to high-level languages.

To understand how a program in a high-level language is translated into machine language using an interpreter or a compiler.

To distinguish between four computer language paradigms.

To understand the procedural paradigm and the interaction between a program unit and data items in the paradigm.

1.2

(3)

Objectives (continued):

To define functional paradigm and understand its applications.

To define a declaration paradigm and understand its applications.

To understand the object-oriented paradigm and the interaction between a program unit and objects in this paradigm.

(4)

1.4

9.1 EVOLUTION

To write a program for a computer, we must use a

computer language. A computer language is a set of

predefined words that are combined into a program

according to predefined rules (syntax). Over the years,

computer languages have evolved from machine

language to assembly languages to high-level

languages.

(5)

Programming language: A set of rules, words, symbols, and codes used to write computer programs

◦ To write a program, you need appropriate software for the programming language you will be using

Categories of programming languages

◦ Low-level languages: Difficult to code in; machine dependent

 Machine language: 1s and 0s

 Assembly language: Includes some names and other symbols

to replace some of the 1s and 0s in machine language

(6)

6

(7)

◦ High-level languages: Closer to natural languages

 Machine independent

 Includes 3GLs (FORTRAN, BASIC, COBOL,C, etc.) and object-oriented languages (Visual Basic, C#, Python, Java, etc.)

 Visual or graphical languages: Use graphical interface to create programs

◦ Fourth-generation languages (4GLs): Even closer to natural languages and easier to work with than high- level

 Declarative rather than procedural

 Includes structured query language (SQL) used with

(8)

1.8

Table 9.1: Code in machine language to add two integers

(9)

Table 9.2: Code in assembly language to add two integers

(10)

#include <stdio.h>

int main( ) {

int num1, num2, sum;

printf("Enter two integers: ");

scanf("%d %d",&num1,&num2); sum=num1+num2;

printf("Sum: %d",sum);

return 0;

}

1.10

Code in High Level Languages

(11)

FORTRAN: High-level programming language used for mathematical, scientific, and engineering applications

◦ Efficient for math,

engineering and

scientific applications

◦ Still used today for high-performance

computing tasks

(weather forecast)

(12)

COBOL: Designed for business transaction processing

◦ Makes extensive use of modules and submodules

◦ Being

phased out in many

organizations

◦ Evolving

(COBOL.NET)

12

(13)

Pascal: Created as a teaching tool to encourage structured programming

◦ Contains a variety of control structures used to

manipulate modules systematically

(14)

BASIC: Easy-to-learn, high-level programming language that was developed to be used by beginning programmers

◦ Visual Basic: Object-oriented version of BASIC; uses a visual environment

14

(15)

C: Designed for system programming

C++: Object-oriented versions of C

C#: Used for Web applications

Objective-C:

For iPhone and other Apple

applications

(16)

Java: High-level, object-oriented programming language frequently used for Web-based

applications

◦ Java programs are compiled into bytecode

◦ Can run on any computer that includes Java Virtual Machine (Java VM)

◦ Can be used to write Java applets

 Scroll text on Web page, games, calculators, etc

◦ Is one of the most popular programming languages today

16

(17)
(18)

Python: Open-source, dynamic, object-oriented language that can be used to develop a variety of applications

◦ Gaming, scientific, database, and Web applications

◦ Only recently gaining a following

18

(19)

 Ruby: Open-source, object-oriented language that can be used to create general-purpose or Web applications

◦ Uses a syntax that is fairly easy to read and write, allowing

programmers to create database-driven Web applications

easily and quickly

(20)

1.20

9.2 TRANSLATION

Programs today are normally written in one of the high-

level languages. To run the program on a computer, the

program needs to be translated into the machine

language of the computer on which it will run. The

program in a high-level language is called the source

program. The translated program in machine language

is called the object program.

(21)

◦ Types of language translators:

 Compilers: Language translator that converts an entire program into machine language before executing it

 Interpreters: Translates one line of code at one time

 Assemblers: Convert assembly

language programs into machine

language

(22)

1.22

(23)

9.3 PROGRAMMING PARADIGMS

Today computer languages are categorized according

to the approach they use to solve a problem. A

paradigm, therefore, is a way in which a computer

language looks at the problem to be solved. We divide

computer languages into four paradigms: procedural

(imperative), object-oriented, functional, and

declarative.

(24)

1.24

(25)

Procedural programming: An approach to program design in which a program is separated into small modules that are called by the main program or another module when needed

◦ Uses procedures (modules, subprograms): Smaller sections of code that perform specific tasks

◦ Allows each procedure to be performed as many times as needed; multiple copies of code not needed

◦ Prior to procedural programming, programs were one large set of instructions (used GOTO statements)

◦ Structured programming: Goes even further, breaking the

program into small modules (Top-down design) that use

basic structures

(26)

1.26

(27)
(28)

Object-oriented programming (OOP): Programs consist of a collection of objects that contain

data and methods to be used with that data

◦ Class: Group of objects that share some common properties

◦ Instance: An individual object in a class

◦ Attributes: Data about the state of an object

◦ Methods: Perform actions on an object

◦ Objects can perform nontraditional actions and be easily used by more than one program

◦ Inheritance between classes improve reuse

28

(29)
(30)

1.30

(31)

Aspect-oriented programming (AOP): Separates

functions so program components can be developed and modified individually from one another

◦ The components can be easily reused with separate nonrelated objects

Adaptive software development: Designed to make program development faster and more efficient and focus on adapting the program as it is being written

◦ Iterative and/or incremental

◦ Includes RAD (rapid application development)

◦ and extreme programming (XP)

◦ Agile software development: Focuses on building small

(32)

1.32

(33)
(34)

1.34

9.4 COMMON CONCEPTS

In this section we conduct a quick navigation through some procedural languages to find common concepts.

Some of these concepts are also available in most

object-oriented languages because, as we explain, an

object-oriented paradigm uses the procedural paradigm

when creating methods.

(35)

Identifiers

Data Types

Variables

Constants

Input and Output

Expressions

Statements

(36)

1.36

Table 9.3: Arithmetic operators

(37)

Table 9.4: Relational operators

(38)

1.38

Table 9.5: Logical operators

(39)
(40)

1.40

(41)

Figure

Updating...

References

Related subjects :