190 likes | 424 Views
Chapter 6: Programming Languages. Computer Science: An Overview Tenth Edition by J. Glenn Brookshear. Chapter 6: Programming Languages. 6.1 Historical Perspective 6.2 Traditional Programming Concepts 6.4 Language Implementation. Figure 6.1 Generations of programming languages.
E N D
Chapter 6:Programming Languages Computer Science: An OverviewTenth Edition by J. Glenn Brookshear
Chapter 6: Programming Languages • 6.1 Historical Perspective • 6.2 Traditional Programming Concepts • 6.4 Language Implementation
Second-generation:Assembly language • A mnemonic system for representing machine instructions • Mnemonic names for op-codes • Identifiers: Descriptive names for memory locations, chosen by the programmer
Assembly Language Characteristics • One-to-one correspondence between machine instructions and assembly instructions • Programmer must think like the machine • Inherently machine-dependent • Converted to machine language by a program called an assembler
Machine language156C166D505630CEC000 Assembly languageLD R5, PriceLD R6, ShippingChargeADDI R0, R5 R6ST R0, TotalCostHLT Program Example
Third Generation Language Turkish, German, English etc. are natural languages but programming languages are formal languages. • Uses high-level primitives • Similar to our pseudocode in Chapter 5 • Machine independent (mostly) • Examples: FORTRAN, COBOL • Each primitive corresponds to a sequence of machine language instructions • Converted to machine language by a program called a compiler
Figure 6.2 The evolution of programming paradigms Programming (software development) paradigms: Alternative approaches to the programming (software development process) process. Imperative (procedural) paradigm: Programming process is the development of a sequence of commands that, when followed, manipulate data to produce the desired result (i.e. find an algorithm to solve the problem). Object-oriented paradigm Software system is a collection of units (called objects) each of which is capable of performing the actions that are related to itself and as well as requesting actions of other objects. Declarative paradigm:Asks programmer to describe the problem to be solved rather than an algorithm to be followed. Agent-oriented paradigm (?) Autonomous, proactive and social objects (a.k.a. dynamic objects). Functional paradigm: A program is constructed by connecting smaller program units (i.e. predefined functions) so that each unit’s outputs are used as inputs to another unit in such a way that the desired overall input-to-output relationship is obtained.
Figure 6.3 A function for checkbook balancing constructed from simpler functions In LISP, (Find_diff (Find_sum (Old_balance Credits) Find_sum (Debits))
Figure 6.4 The composition of a typical imperative program or program unit Statement categories in imperative and object-oriented languages: Declarative statements Customized terminology that is used later in the program. E.g. Names of data items. Imperative statements Description of steps in the underlying algorithms Comments Statements written into the code in any langugage in order to improve the human readability of the program.
Data Types Variable: Descriptive names (rather than numeric addresses) that refer to main memory locations. Changing the values in such locations results in value changes for the variable. Data type: Type of the associated variable. It encompasses both the manner in which the data item (named by its variable) is encoded and the operations that can be performed on that data (or in general the variable). • Integer: Whole numbers • Real (float): Numbers with fractions • Character: Symbols • Boolean: True/false
Variable Declarations float Length, Width; int Price, Total, Tax; char Symbol;
Figure 6.5 A two-dimensional array with two rows and nine columns Data structure: A conceptual arrangement of data. Homogeneous array: A block of values of the same type such as one-dimensional list, two-dimensional list with rows and columns and higher dimensional tables. Indices: Integer values that specify rows, columns etc. of the elements of a homogeneous array.
Figure 6.6 The conceptual structure of the heterogeneous array Employee Heterogeneous array: Block of data in which different elements can have different types. An example in C: struct{char Name[25]; int Age; float SkillRating;} Employee; Employee.Age = Employee.Age + 1; Employee.SkillRating = 72.5; Declaration part Imperative part
Figure 6.7 The for loop structure and its representation in C++, C#, and Java Comments: provide an easy understanding of program statements. They are explanatory statements inserted within program statements. In C++, C# and Java, /* This is a comment */ // This is a comment