1.1 McGraw-Hill The McGraw-Hill Companies, Inc., 2000
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
Objectives (continued): To understand the object-oriented paradigm and the interaction between a program unit and objects in this paradigm. To define functional paradigm and understand its applications. To define a declaration paradigm and understand its applications. To define common concepts in procedural and object-oriented languages. 1.3
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. 1.4
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 5
6
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 highlevel Declarative rather than procedural Includes structured query language (SQL) used with databases 7
Table 9.1: Code in machine language to add two integers 1.8
Table 9.2: Code in assembly language to add two integers 1.9
Code in High Level Languages #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
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)
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
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
C: Designed for system programming C++: Object-oriented versions of C C#: Used for Web applications Objective-C: For iphone and other Apple applications 15
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
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
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 19
9.2 TRANSLATION Programs today are normally written in one of the highlevel 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. 1.20
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 21
1.22
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. 1.23
1.24
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 25
1.26
1.27
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
1.29
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 functional program pieces during the project
1.32
1.33
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. 1.34
Identifiers Data Types Variables Constants Input and Output Expressions Statements 1.35
Table 9.3: Arithmetic operators 1.36
Table 9.4: Relational operators 1.37
Table 9.5: Logical operators 1.38
1.39
1.40
1.41